Here you can find the source of executeBatchedUpdate(Connection conn, String sql, int size)
public static void executeBatchedUpdate(Connection conn, String sql, int size) throws SQLException
//package com.java2s; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { public static void executeBatchedUpdate(Connection conn, String sql, int size) throws SQLException { System.out.println("Update SQL: " + sql); PreparedStatement pstmt = null; try {/* ww w. j a v a 2 s . c o m*/ 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"); pstmt.setString(4, "$8000.00"); pstmt.setString(5, "Crystal Orange"); pstmt.addBatch(); } pstmt.executeBatch(); if (!conn.getAutoCommit()) { conn.commit(); } } catch (SQLException e) { throw e; } finally { close(pstmt); } } public static void close(Connection conn) { if (null != conn) { try { conn.close(); conn = null; } catch (SQLException e) { } } } public static void close(Statement stmt) { if (null != stmt) { try { stmt.close(); stmt = null; } catch (SQLException e) { } } } public static void close(ResultSet rs, Statement stmt) { if (null != rs) { try { rs.close(); rs = null; } catch (SQLException e) { } } if (null != stmt) { try { stmt.close(); stmt = null; } catch (SQLException e) { } } } }