Advertisement
Jnk1296

PreparedStatement

Mar 2nd, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. public PreparedStatement getStatement(Connection c) {
  2.         try {
  3.             PreparedStatement prepStmt = c.prepareStatement(this.SQL);
  4.  
  5.             if (this.values != null) {
  6.                 for (int i = 1; i < this.values.length; i++) {
  7.                     if (this.values[i] instanceof String) {
  8.                         prepStmt.setString(i, this.values[i].toString());
  9.                         continue;
  10.                     }
  11.  
  12.                     if (this.values[i] instanceof Integer) {
  13.                         prepStmt.setInt(i, (Integer) this.values[i]);
  14.                         continue;
  15.                     }
  16.  
  17.                     this.plugin.sendConsoleMessage(Level.SEVERE, this.plugin
  18.                             .getLocalizationManager()
  19.                             .getLocalString("BAD_SQL_INPUT"));
  20.                 }
  21.             }
  22.  
  23.             return prepStmt;
  24.         } catch (Exception e) {
  25.             this.plugin.sendConsoleMessage(Level.SEVERE, this.plugin
  26.                     .getLocalizationManager()
  27.                     .getLocalString("DB_PREP_STMT_ERR"));
  28.             e.printStackTrace();
  29.         }
  30.  
  31.         return null;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement