/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package niagaratest; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author bj136805 */ public class NiagaraTest implements Runnable { static final String URL = "jdbc:mysql://localhost/?user=root&cacheServerConfiguration=true&"; private int table_no; private int no_of_rows; NiagaraTest(int table_no, int no_of_rows) { this.table_no = table_no; this.no_of_rows = no_of_rows; } public static void main(String[] args) throws SQLException, ClassNotFoundException { int no_of_rows = 10000; int no_of_threads = 16; Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection(URL); Statement stm = con.createStatement(); try { stm.executeUpdate("drop schema niagaratest"); } catch (SQLException e) { // Ignore of schema alraedy there } stm.executeUpdate("create schema niagaratest"); stm.close(); con.close(); for (int i = 0; i < no_of_threads; i++) { new Thread(new NiagaraTest(i, no_of_rows)).start(); } } public void run() { try { System.out.println("Thread " + table_no + " started"); String tableName = "niagaratest.tab" + table_no; Connection c = DriverManager.getConnection(URL); Statement stm = c.createStatement(); stm.executeUpdate("create table " + tableName + " (i integer) engine=falcon"); stm.close(); PreparedStatement s = c.prepareStatement("insert into " + tableName + " values (?)"); for (int i = 0; i < no_of_rows; i++) { s.setInt(1, i); s.executeUpdate(); } s.close(); c.close(); System.out.println("Thread " + table_no + " finished"); } catch (SQLException ex) { Logger.getLogger(NiagaraTest.class.getName()).log(Level.SEVERE, null, ex); } } }