Advertisement
Jampire

Untitled

Jul 12th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. private PreparedStatement fill(PreparedStatement ps, Object... args) throws SQLException {
  2. for (int i = 0; i < args.length; i++)
  3. ps.setObject(i + 1, args[i]);
  4. return ps;
  5. }
  6.  
  7.  
  8.  
  9. public void select(@Language("SQL") String sql, SelectHandler handler, Object... args) {
  10. if (this.connection == null)
  11. return;
  12. if (handler == null)
  13. handler = rs -> {};
  14. try (PreparedStatement ps = this.fill(this.connection.prepareStatement(sql), args)) {
  15. try (ResultSet rs = ps.executeQuery()) {
  16. handler.debug(sql + " " + Arrays.toString(args));
  17. handler.execute(rs);
  18. }
  19. this.stats.querySelect++;
  20. } catch (Exception e) {
  21. this.handleException(e, handler);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement