Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected int executeInsert(String query, ResultSetCallable callable, Column<?>...columns)
- {
- int affectedRows = 0;
- // Automatic resource management for handling/closing objects.
- try (
- Connection connection = getConnection();
- PreparedStatement preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS)
- )
- {
- for (int i=0; i < columns.length; i++)
- {
- columns[i].setValue(preparedStatement, i+1);
- }
- affectedRows = preparedStatement.executeUpdate();
- if (callable != null)
- {
- callable.processResultSet(preparedStatement.getGeneratedKeys());
- }
- }
- catch (SQLException exception)
- {
- exception.printStackTrace();
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- }
- return affectedRows;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement