import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Random; /** * * @author McEase * */ public class Partition { public static void main (String [] args) { if (args.length < 2) { System.out.println("Usage: java Partition "); System.exit(1); } final String host = args[0]; final String user = args[1]; final String pwd = args.length == 2 ? "" : args[2]; for (int i = 0; i < 100; i++) { final int t = i; new Thread () { public void run () { Connection conn = null; PreparedStatement pstmt = null; try { Random rand = new Random(); Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://" + host + "/test", user, pwd); conn.setAutoCommit(false); pstmt = conn.prepareStatement("insert into partest values (?, ?, ?, ?, now())"); for (int i = 0; i < 1000; i++) { for (int j = 0; j < 200; j++) { pstmt.setString(1, t + "," + i + "," + j); pstmt.setInt(2, t); pstmt.setInt(3, i); pstmt.setInt(4, j); pstmt.execute(); } Thread.sleep(rand.nextInt(100)); conn.commit(); if (t == 0) { if ((i % 50) == 0 && i > 0 && i < 1000) { System.out.println("about " + (5 * i / 50) + "% finished ..."); } } } } catch (Exception e) { e.printStackTrace(); } finally { if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) {} } if (conn != null) { try { conn.close(); } catch (SQLException e) {} } } } }.run(); } } }