Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. protected int executeInsert(String query, ResultSetCallable callable, Column<?>...columns)
  2. {
  3. int affectedRows = 0;
  4.  
  5. // Automatic resource management for handling/closing objects.
  6. try (
  7. Connection connection = getConnection();
  8. PreparedStatement preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS)
  9. )
  10. {
  11. for (int i=0; i < columns.length; i++)
  12. {
  13. columns[i].setValue(preparedStatement, i+1);
  14. }
  15.  
  16. affectedRows = preparedStatement.executeUpdate();
  17.  
  18. if (callable != null)
  19. {
  20. callable.processResultSet(preparedStatement.getGeneratedKeys());
  21. }
  22. }
  23. catch (SQLException exception)
  24. {
  25. exception.printStackTrace();
  26. }
  27. catch (Exception exception)
  28. {
  29. exception.printStackTrace();
  30. }
  31.  
  32. return affectedRows;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement