Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void insert(String[] columnsArray, String[] valuesArray, String table){
- String columns = String.join(", ", columnsArray);
- String values = "'" + String.join("', '", valuesArray) + "'";
- String check = values.substring(values.length()-2, values.length());
- if(check.equals("''")){
- values = values.substring(0, values.length()-2) + "null";
- }
- String sql = "INSERT INTO " + table + " (" + columns + ") VALUES (" + values + ")";
- System.out.println(sql);
- try{
- stmt = conn.createStatement();
- stmt.executeQuery(sql);
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement