performance fixes and fix for core dump in test tools/csql/test029.ksh
[csql.git] / examples / jdbc / gwexample.java
blob3fc648eae82ec07ed01acb789a1b20b6a365e4d3
1 import java.sql.*;
2 public class gwexample
4 public static void main(String[] args)
6 try
8 Class.forName("csql.jdbc.JdbcSqlDriver");
9 Connection con = DriverManager.getConnection("jdbc:gateway", "root", "manager");
10 Statement cStmt = con.createStatement();
12 PreparedStatement stmt = null, selStmt= null;
13 stmt = con.prepareStatement("INSERT INTO t1 (f1, f2) VALUES (?, ?);");
14 int count =0;
15 int ret =0;
16 for (int i =0 ; i< 10 ; i++) {
17 stmt.setInt(1, i);
18 stmt.setString(2, String.valueOf(i+100));
19 ret = stmt.executeUpdate();
20 if (ret != 1) break; //error
21 count++;
23 stmt.close();
24 con.commit();
25 System.out.println("Total Rows inserted " + count);
27 count =0;
28 stmt = con.prepareStatement("UPDATE t1 SET f2 = ? WHERE f1 = ?;");
29 for (int i =0 ; i< 10 ; i +=2) {
30 stmt.setString(1, String.valueOf(i+200));
31 stmt.setInt(2, i);
32 ret = stmt.executeUpdate();
33 if (ret != 1) break; //error
34 count++;
36 stmt.close();
37 con.commit();
38 System.out.println("Total Rows updated " + count);
40 count =0;
41 stmt = con.prepareStatement("DELETE FROM t1 WHERE f1 = ?;");
42 for (int i =0 ; i< 10 ; i +=3) {
43 stmt.setInt(1, i);
44 ret = stmt.executeUpdate();
45 if (ret != 1) break; //error
46 count++;
48 stmt.close();
49 con.commit();
50 System.out.println("Total Rows deleted " + count);
52 count =0;
53 selStmt = con.prepareStatement("SELECT * from t1 where f1 = ?;");
54 ResultSet rs = null;
55 for (int i =0 ; i< 10 ; i++) {
56 selStmt.setInt(1, i);
57 rs = selStmt.executeQuery();
58 while (rs.next())
60 System.out.println("Tuple value is " + rs.getInt(1)+ " "+ rs.getString(2));
61 count++;
63 rs.close();
65 selStmt.close();
66 con.commit();
67 System.out.println("Total Rows selected " + count);
68 con.close();
70 catch(Exception e) {
71 System.out.println("Exception in Test: "+e);
72 e.printStackTrace();