@Override public void attach() throws SQLException { try { if (isAttached()) { throw new SQLException("Already attached to a service"); } final ServiceParameterBuffer spb = PARAMETER_CONVERTER.toServiceParameterBuffer(connection); final byte[] serviceName = getEncoding().encodeToCharset(connection.getAttachUrl()); final byte[] spbArray = spb.toBytesWithType(); synchronized (getSynchronizationObject()) { try { clientLibrary.isc_service_attach( statusVector, (short) serviceName.length, serviceName, handle, (short) spbArray.length, spbArray); processStatusVector(); } catch (SQLException ex) { safelyDetach(); throw ex; } catch (Exception ex) { safelyDetach(); // TODO Replace with specific error (eg native client error) throw new FbExceptionBuilder() .exception(ISCConstants.isc_network_error) .messageParameter(connection.getServerName()) .cause(ex) .toSQLException(); } setAttached(); afterAttachActions(); } } catch (SQLException e) { exceptionListenerDispatcher.errorOccurred(e); throw e; } }