Java Utililty Methods SQL Batch Execute

List of utility methods to do SQL Batch Execute

Description

The list of methods to do SQL Batch Execute are organized into topic(s).

Method

int[]executeAsBatch(Connection con, List sqlList)
execute As Batch
return executeAsBatch(con, sqlList.toArray(new String[] {}));
voidexecuteBatch(File file, Connection con, String pluginName)
Read a *.sql batch containing SQL statements.
executeBatch(new BufferedReader(new FileReader(file)), con, pluginName);
voidexecuteBatch(PreparedStatement prepStmt)
execute Batch
try {
    prepStmt.executeBatch();
} catch (SQLException sqle) {
    sqle.getNextException().printStackTrace();
    throw new RuntimeException(sqle);
int[]executeBatch(PreparedStatement ps)
execute Batch
assert locked : "Database isn't locked";
int[] a = ps.executeBatch();
return a;
voidexecuteBatchedUpdate(Connection conn, String sql, int size)
execute Batched Update
System.out.println("Update SQL: " + sql);
PreparedStatement pstmt = null;
try {
    pstmt = conn.prepareStatement(sql);
    for (int i = 0; i < size; i++) {
        pstmt.setString(1, 110 + i + "");
        pstmt.setString(2, "Beijng");
        pstmt.setString(3, "Kylin Soong");
...
voidexecuteBatchedUpdateDataType(Connection conn, String sql)
execute Batched Update Data Type
System.out.println("Update SQL: " + sql);
byte b = 127;
short s = 10000;
long l = 1000000;
float f = 3.6f;
double d = 3.6;
int in = 100;
BigDecimal decimal = new BigDecimal(l);
...
voidexecuteBatches(PreparedStatement... statements)
Execute batches for PreparedStatements.
for (PreparedStatement statement : statements) {
    statement.executeBatch();