private synchronized Connection getConnection() throws SQLException { Connection connection = dbUtil.getConnection(); connection.setAutoCommit(true); return connection; } }
private Connection getConnection() throws CredentialStoreException { try { return this.dbUtil.getConnection(); } catch (SQLException e) { throw new CredentialStoreException("Unable to retrieve database connection.", e); } }
public Connection getConnection() throws Exception { DBUtil dbUtil = getDbUtil (); Connection connection = dbUtil.getConnection(); connection.setAutoCommit(true); return connection; }
/** * Create table utility method. * * @param sql * SQL to be executed. * @throws SQLException * If an error occurred while creating the table. */ public void executeSQL(String sql) throws SQLException { Connection connection = getConnection(); PreparedStatement ps = connection.prepareStatement(sql); try { ps.executeUpdate(); connection.commit(); } finally { try { if (ps != null) { ps.close(); } connection.close(); } catch (Exception ignore) { log.error("An error occurred while closing database connections ", ignore); } } }
Connection connection = getConnection();
public static void waitTillServerStarts() { DBUtil dbUtil = null; try { dbUtil = new DBUtil(getJDBCUrl(), getUserName(), getPassword(), getDriver()); } catch (Exception e) { // ignore } Connection connection = null; try { if (dbUtil != null) { connection = dbUtil.getConnection(); } } catch (Throwable e) { // ignore } while (connection == null) { try { Thread.sleep(1000); try { if (dbUtil != null) { connection = dbUtil.getConnection(); } } catch (SQLException e) { // ignore } } catch (InterruptedException e) { // ignore } } }
public void writeCredentials(Credential credential) throws CredentialStoreException { SSHCredential sshCredential = (SSHCredential) credential; Connection connection = null; try { connection = dbUtil.getConnection(); // First delete existing credentials credentialsDAO.deleteCredentials(sshCredential.getGateway(), sshCredential.getToken(), connection); // Add the new certificate credentialsDAO.addCredentials(sshCredential.getGateway(), credential, connection); if (!connection.getAutoCommit()) { connection.commit(); } } catch (SQLException e) { if (connection != null) { try { connection.rollback(); } catch (SQLException e1) { logger.error("Unable to rollback transaction", e1); } } throw new CredentialStoreException("Unable to retrieve database connection.", e); } finally { DBUtil.cleanup(connection); } }
public void writeCredentials(Credential credential) throws CredentialStoreException { CertificateCredential certificateCredential = (CertificateCredential) credential; Connection connection = null; try { connection = dbUtil.getConnection(); // Write community user writeCommunityUser(certificateCredential.getCommunityUser(), credential.getToken(), connection); // First delete existing credentials credentialsDAO.deleteCredentials(certificateCredential.getCommunityUser().getGatewayName(), certificateCredential.getToken(), connection); // Add the new certificate credentialsDAO.addCredentials(certificateCredential.getCommunityUser().getGatewayName(), credential, connection); if (!connection.getAutoCommit()) { connection.commit(); } } catch (SQLException e) { if (connection != null) { try { connection.rollback(); } catch (SQLException e1) { log.error("Unable to rollback transaction", e1); } } throw new CredentialStoreException("Unable to retrieve database connection.", e); } finally { DBUtil.cleanup(connection); } }