import java.io.*; import java.text.*; import java.util.Date; import java.sql.PreparedStatement; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.Driver; import java.sql.DriverManager; import java.sql.DriverPropertyInfo; import java.sql.SQLException; import java.sql.Statement; import java.sql.ResultSet; import java.sql.Timestamp; public class issue_batch_stmt { /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { try { com.mysql.jdbc.jdbc2.optional.MysqlDataSource ds = new com.mysql.jdbc.jdbc2.optional.MysqlDataSource(); ds.setURL("jdbc:mysql://localhost:3306/test"); ds.setUser("root"); ds.setPassword(""); ds.setAllowMultiQueries(true); ds.setRewriteBatchedStatements(false); ds.setUseServerPreparedStmts(false); System.out.println("Opening connection ..."); Connection con = ds.getConnection(); Statement stmt = con.createStatement(); System.out.println("Creating table ..."); stmt.executeUpdate("drop table if exists tab_batch_stmt"); stmt.executeUpdate("create table tab_batch_stmt(id int auto_increment primary key, vc varchar(32))engine=innodb"); System.out.println("Adding statements to batch ..."); PreparedStatement pstmt = con.prepareStatement("insert into tab_batch_stmt (id, vc) values (?, ?)"); pstmt.setInt(1, 1); pstmt.setString(2, "11111111 aaaaaa"); pstmt.addBatch(); pstmt.setInt(1, 2); pstmt.setString(2, "22222222 bbbbbb"); pstmt.addBatch(); pstmt.setInt(1, 3); pstmt.setString(2, "33333333 cccccc"); pstmt.addBatch(); pstmt.setInt(1, 4); pstmt.setString(2, "44444444 dddddd"); pstmt.addBatch(); pstmt.setInt(1, 5); pstmt.setString(2, "55555555 eeeeee"); pstmt.addBatch(); System.out.println("Execute batch ..."); pstmt.executeBatch(); System.out.println("Closing connection ..."); con.close(); System.out.println("Bye"); } catch(SQLException ex) { System.out.printf(ex.getMessage()); ex.printStackTrace(); } } }