Advertisement
lemansky

Untitled

Dec 2nd, 2020
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1.  
  2.     public void update(String[] columnsArray, String[] valuesArray, String whereCol, String whereVal, String table){
  3.        String sql = " UPDATE " + table + " SET ";
  4.         for (int i = 0; i < columnsArray.length; i++) {
  5.             sql += columnsArray[i] + " = '" + valuesArray[i] + "', ";
  6.         }
  7.         sql = sql.substring(0, sql.length() - 2);
  8.         sql += " WHERE " + whereCol + " = '" + whereVal + "'";
  9.         try{
  10.             stmt = conn.createStatement();
  11.             stmt.executeQuery(sql);
  12.         } catch (SQLException e) {
  13.             System.out.println(e.getMessage());
  14.         }
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement