Skip to content

Instantly share code, notes, and snippets.

@nbkhope
Created December 13, 2017 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbkhope/bc3ddd0ca77f57304cbe6708ee37abbb to your computer and use it in GitHub Desktop.
Save nbkhope/bc3ddd0ca77f57304cbe6708ee37abbb to your computer and use it in GitHub Desktop.
Efficient JDBC Multiple Queries using PreparedStatement Batch
connection.setAutoCommit(false);
PreparedStatement preparedStatement = connection.prepareStatement(someQuery);
for (Record record : records) {
// do your stuff (e.g. preparedStatement.setString(1, name);
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
connection.commit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment