Here you can find the source of createInsertPrepareStatement(Connection conn, String tableName, String[] dataColumnNames)
public static PreparedStatement createInsertPrepareStatement(Connection conn, String tableName, String[] dataColumnNames) throws Exception
//package com.java2s; //License from project: Apache License import java.sql.*; public class Main { private static String[] insertSqlTpl = { "INSERT INTO ", "", " Values(?", "", ",?)" }; public static PreparedStatement createInsertPrepareStatement(Connection conn, String tableName, String[] dataColumnNames) throws Exception { PreparedStatement preparedStatement = null; try {//from w w w . j a va2 s . co m StringBuilder insertQueryBuf = new StringBuilder(); insertQueryBuf.append(insertSqlTpl[0]); insertQueryBuf.append(tableName); insertQueryBuf.append("(PKEYIDX"); for (int idx = 0; idx < dataColumnNames.length; idx++) { insertQueryBuf.append(","); insertQueryBuf.append(dataColumnNames[idx]); } insertQueryBuf.append(",C_TIME) "); insertQueryBuf.append(insertSqlTpl[2]); for (int idx = 0; idx < dataColumnNames.length; idx++) { insertQueryBuf.append(","); insertQueryBuf.append("?"); } insertQueryBuf.append(insertSqlTpl[4]); preparedStatement = conn.prepareStatement(insertQueryBuf.toString()); } catch (Exception e) { throw e; } return preparedStatement; } }