2 import java
.util
.Random
;
3 public class JDBCPopulate
5 public static Random generator
= new Random();
6 public static int getRandom(int end
)
8 double val
= generator
.nextDouble();
13 public static void populate(Connection con
)throws Exception
15 PreparedStatement stmt
= null;
17 String buf
= "insert into big1 values(?,?,0,2,0,10,50,688,1950,4950,9950,1,100,?,'GXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXXA','OXXXXXXXXXXXXXXXXXXXXXXXXXOXXXXXXXXXXXXXXXXXXXXXXXXO');";
19 stmt
= con
.prepareStatement(stmtStr
);
22 for(int i
=0; i
<10000; i
++){
25 stmt
.setString(3, "Value" + i
);
26 ret
= stmt
.executeUpdate();
28 System
.out
.println("Table population failed");
31 if (i
% 1000 == 0) con
.commit();
36 System
.out
.println("Records Inserted into big1 table: "+count
);
38 stmtStr
= "insert into big2 values(?,?,0,2,0,10,50,688,1950,4950,9950,1,100,'AXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXX','GXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXXA','OXXXXXXXXXXXXXXXXXXXXXXXXXOXXXXXXXXXXXXXXXXXXXXXXXXO');";
39 stmt
= con
.prepareStatement(stmtStr
);
41 for(int i
=0; i
<10000; i
++){
44 ret
= stmt
.executeUpdate();
46 System
.out
.println("Table population failed");
49 if (i
% 1000 == 0) con
.commit();
54 System
.out
.println("Records Inserted into big2 table: "+count
);
56 stmtStr
= "insert into small values(?,?,0,2,0,10,50,688,1950,4950,9950,1,100,'AXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXX','GXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXXA','OXXXXXXXXXXXXXXXXXXXXXXXXXOXXXXXXXXXXXXXXXXXXXXXXXXO');";
57 stmt
= con
.prepareStatement(stmtStr
);
59 for(int i
=0; i
<1000; i
++){
62 ret
= stmt
.executeUpdate();
64 System
.out
.println("Table population failed");
67 if (i
% 100 == 0) con
.commit();
72 System
.out
.println("Records Inserted into small table: "+count
);
77 public static void main(String
[] args
)
81 Connection con
= null;
82 Class
.forName("csql.jdbc.JdbcSqlDriver");
83 con
= DriverManager
.getConnection("jdbc:csql", "root", "manager");
84 con
.setAutoCommit(false);
85 con
.setTransactionIsolation(Connection
.TRANSACTION_READ_COMMITTED
);
86 Statement cStmt
= con
.createStatement();
88 cStmt
.execute("CREATE TABLE small (unique1 INT NOT NULL , unique2 INT NOT NULL , two INT NOT NULL , four INT NOT NULL , ten INT NOT NULL , twenty INT NOT NULL , onepercent INT NOT NULL , tenpercent INT NOT NULL , twentypercent INT NOT NULL , fiftypercent INT NOT NULL , unique3 INT NOT NULL , evenonepercent INT NOT NULL , oddonepercent INT NOT NULL , stringu1 CHAR (52) NOT NULL , stringu2 CHAR (52) NOT NULL , string4 CHAR (52) NOT NULL );");
89 cStmt
.execute("CREATE TABLE big1 (unique1 INT NOT NULL , unique2 INT NOT NULL , two INT NOT NULL , four INT NOT NULL , ten INT NOT NULL , twenty INT NOT NULL , onepercent INT NOT NULL , tenpercent INT NOT NULL , twentypercent INT NOT NULL , fiftypercent INT NOT NULL , unique3 INT NOT NULL , evenonepercent INT NOT NULL , oddonepercent INT NOT NULL , stringu1 CHAR (52) NOT NULL , stringu2 CHAR (52) NOT NULL , string4 CHAR (52) NOT NULL );");
90 cStmt
.execute("CREATE TABLE big2 (unique1 INT NOT NULL , unique2 INT NOT NULL , two INT NOT NULL , four INT NOT NULL , ten INT NOT NULL , twenty INT NOT NULL , onepercent INT NOT NULL , tenpercent INT NOT NULL , twentypercent INT NOT NULL , fiftypercent INT NOT NULL , unique3 INT NOT NULL , evenonepercent INT NOT NULL , oddonepercent INT NOT NULL , stringu1 CHAR (52) NOT NULL , stringu2 CHAR (52) NOT NULL , string4 CHAR (52) NOT NULL );");
93 }catch(Exception e
){e
.printStackTrace(); System
.out
.println("Error creating index");}
97 } catch(Exception e
) {
98 System
.out
.println("Exception in Test: "+e
);