Java SQL PreparedStatement createInsertPrepareStatement(Connection conn, String tableName, String[] dataColumnNames)

Here you can find the source of createInsertPrepareStatement(Connection conn, String tableName, String[] dataColumnNames)

Description

create Insert Prepare Statement

License

Apache License

Declaration

public static PreparedStatement createInsertPrepareStatement(Connection conn, String tableName,
            String[] dataColumnNames) throws Exception 

Method Source Code

//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;
    }
}

Related

  1. closePS(PreparedStatement argPreparedStatement)
  2. closeSilentlyPreparedStatement(PreparedStatement stmt)
  3. closeStatement(PreparedStatement preparedStatement)
  4. closeStatement(PreparedStatement ps)
  5. closeStatement(PreparedStatement theStatement)
  6. createPreparedStatement(Connection conn, String sql, String[] args)
  7. createProjectInfo(PreparedStatement ps, long projectId, long projectInfoTypeId, String value, long modUserId)
  8. deleteOldData(Connection connection, PreparedStatement stmt, String funcId)
  9. fillArgs(Object[][] args, PreparedStatement pstmt, int i)