code reorg
[csql.git] / demo / wisc / JDBCPopulate.java
blob400cf836ef3f0da2c48e11a862da86c60d355e33
1 import java.sql.*;
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();
9 val *=end;
10 return (int)(val);
13 public static void populate(Connection con)throws Exception
15 PreparedStatement stmt = null;
16 String stmtStr="";
17 String buf = "insert into big1 values(?,?,0,2,0,10,50,688,1950,4950,9950,1,100,?,'GXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXXA','OXXXXXXXXXXXXXXXXXXXXXXXXXOXXXXXXXXXXXXXXXXXXXXXXXXO');";
18 stmtStr = buf;
19 stmt = con.prepareStatement(stmtStr);
20 int count = 0;
21 int ret =0;
22 for(int i=0; i<10000; i++){
23 stmt.setInt(1, i);
24 stmt.setInt(2, i);
25 stmt.setString(3, "Value" + i);
26 ret = stmt.executeUpdate();
27 if(ret!=1) {
28 System.out.println("Table population failed");
29 return;
31 if (i % 1000 == 0) con.commit();
32 count++;
34 con.commit();
35 stmt.close();
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);
40 count = 0;
41 for(int i=0; i<10000; i++){
42 stmt.setInt(1, i);
43 stmt.setInt(2, i);
44 ret = stmt.executeUpdate();
45 if(ret!=1) {
46 System.out.println("Table population failed");
47 return;
49 if (i % 1000 == 0) con.commit();
50 count++;
52 con.commit();
53 stmt.close();
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);
58 count = 0;
59 for(int i=0; i<1000; i++){
60 stmt.setInt(1, i);
61 stmt.setInt(2, i);
62 ret = stmt.executeUpdate();
63 if(ret!=1) {
64 System.out.println("Table population failed");
65 return;
67 if (i % 100 == 0) con.commit();
68 count++;
70 con.commit();
71 stmt.close();
72 System.out.println("Records Inserted into small table: "+count);
74 return;
77 public static void main(String[] args)
79 try
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();
87 try {
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 );");
91 cStmt.close();
92 con.commit();
93 }catch(Exception e ){e.printStackTrace(); System.out.println("Error creating index");}
94 populate(con);
95 con.close();
97 } catch(Exception e) {
98 System.out.println("Exception in Test: "+e);
99 e.printStackTrace();