Advertisement
lemansky

Untitled

Nov 19th, 2020
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1.  public void insert(String[] columnsArray, String[] valuesArray, String table){
  2.         String columns = String.join(", ", columnsArray);
  3.        
  4.         String values = "'" + String.join("', '", valuesArray) + "'";
  5.         String check = values.substring(values.length()-2, values.length());
  6.         if(check.equals("''")){
  7.             values = values.substring(0, values.length()-2) + "null";
  8.         }
  9.         String sql = "INSERT INTO " + table + " (" + columns + ") VALUES (" + values + ")";
  10.         System.out.println(sql);
  11.         try{
  12.             stmt = conn.createStatement();
  13.             stmt.executeQuery(sql);
  14.         } catch (SQLException e) {
  15.             System.out.println(e.getMessage());
  16.         }
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement