Skip to content

Instantly share code, notes, and snippets.

@gilfernandes
Last active August 29, 2015 14:01
Show Gist options
  • Save gilfernandes/c5ee07737f274e294100 to your computer and use it in GitHub Desktop.
Save gilfernandes/c5ee07737f274e294100 to your computer and use it in GitHub Desktop.
How to use connection pools
public static ResultSet executeSingleQuery(String query) throws ConnectorException {
Connection conn = null;
ResultSet data = null;
PreparedStatement stmt = null;
try {
conn = ConnectionFactory.LARGE.getConnection(dbDriver, dbUrl, dbUserName, dbPassword);
log.log(Level.INFO, "Query: {0}", query);
data = conn.prepareStatement(query).executeQuery();
} catch (final SQLException sqle) {
log.log(Level.INFO, "Error SQLException: {0}", sqle.getMessage());
throw new ConnectorException(sqle, null, null);
} finally {
ConnectionFactory.LARGE.close(stmt);
ConnectionFactory.LARGE.close(conn);
}
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment