public static String createInsertQuery(String table,String[] fieldNames){
  if (fieldNames == null) {
    throw new IllegalArgumentException("Field names may not be null");
  }
  StringBuilder insertQuery=new StringBuilder();
  insertQuery.append("INSERT INTO ");
  insertQuery.append(table);
  if (fieldNames.length > 0 && fieldNames[0] != null) {
    insertQuery.append(" (");
    for (int i=0; i < fieldNames.length; i++) {
      insertQuery.append(fieldNames[i]);
      if (i != fieldNames.length - 1) {
        insertQuery.append(",");
      }
    }
    insertQuery.append(")");
  }
  insertQuery.append(" VALUES (");
  for (int i=0; i < fieldNames.length; i++) {
    insertQuery.append("?");
    if (i != fieldNames.length - 1) {
      insertQuery.append(",");
    }
  }
  insertQuery.append(")");
  LOG.info("Insert into: ");
  LOG.info(insertQuery.toString());
  return insertQuery.toString();
}

public static String createInsertQuery ( String table , String [ ] fieldNames ) { if ( fieldNames == null ) { throw new IllegalArgumentException ( "Field names may not be null" ) ; } StringBuilder insertQuery = new StringBuilder ( ) ; insertQuery . append ( "INSERT INTO " ) ; insertQuery . append ( table ) ; if ( fieldNames . length > 0 && fieldNames [ 0 ] != null ) { insertQuery . append ( " (" ) ; for ( int i = 0 ; i < fieldNames . length ; i ++ ) { insertQuery . append ( fieldNames [ i ] ) ; if ( i != fieldNames . length - 1 ) { insertQuery . append ( "," ) ; } } insertQuery . append ( ")" ) ; } insertQuery . append ( " VALUES (" ) ; for ( int i = 0 ; i < fieldNames . length ; i ++ ) { insertQuery . append ( "?" ) ; if ( i != fieldNames . length - 1 ) { insertQuery . append ( "," ) ; } } insertQuery . append ( ")" ) ; LOG . info ( "Insert into: " ) ; LOG . info ( insertQuery . toString ( ) ) ; return insertQuery . toString ( ) ; }
creates a prepared statement to insert data into a table .
