import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.util.Properties; public class CreateTable { private static final int NUM_ROWS = 10000000; // 10 million rows each 128 bytes private static final int BATCH_SIZE = 1024*1024; public static void main(String[] args) throws Exception { Properties props = new Properties(); props.put("user", "mySQL64621"); props.put("password", "1234"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/mySQL64621", props); connection.setAutoCommit(false); connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); PreparedStatement createTable = connection.prepareStatement("CREATE TABLE test (" + "field0 BIGINT, field1 BIGINT, field2 BIGINT, field3 BIGINT," + "field4 BIGINT, field5 BIGINT, field6 BIGINT, field7 BIGINT," + "field8 BIGINT, field9 BIGINT, field10 BIGINT, field11 BIGINT," + "field12 BIGINT, field13 BIGINT, field14 BIGINT, field15 BIGINT) ENGINE = MYISAM"); createTable.execute(); PreparedStatement insert = connection.prepareStatement("INSERT INTO test (" + "field0, field1, field2, field3, " + "field4, field5, field6, field7, " + "field8, field9, field10, field11, " + "field12, field13, field14, field15" + ") VALUES (" + "?,?,?,?," + "?,?,?,?," + "?,?,?,?," + "?,?,?,?)"); long sillyCounter = 0; for(int row = 0; row < NUM_ROWS; row++){ for(int field = 0; field < 16; field++){ insert.setLong(field + 1, sillyCounter++); } insert.addBatch(); if (row % BATCH_SIZE == 0){ System.out.println(row * 100 / NUM_ROWS + "%"); insert.executeBatch(); } } insert.executeBatch(); connection.commit(); } }