comparison tests/Test_Cautocommit.java @ 0:a5a898f6886c

Copy of MonetDB java directory changeset e6e32756ad31.
author Sjoerd Mullender <sjoerd@acm.org>
date Wed, 21 Sep 2016 09:34:48 +0200 (2016-09-21)
parents
children 04fbf3655452
comparison
equal deleted inserted replaced
-1:000000000000 0:a5a898f6886c
1 /*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V.
7 */
8
9 import java.sql.*;
10
11 public class Test_Cautocommit {
12 public static void main(String[] args) throws Exception {
13 Class.forName("nl.cwi.monetdb.jdbc.MonetDriver");
14 Connection con1 = DriverManager.getConnection(args[0]);
15 Connection con2 = DriverManager.getConnection(args[0]);
16 Statement stmt1 = con1.createStatement();
17 Statement stmt2 = con2.createStatement();
18 ResultSet rs = null;
19 //DatabaseMetaData dbmd = con.getMetaData();
20
21 // >> true: auto commit should be on by default
22 System.out.println("0. true\t" + con1.getAutoCommit());
23 System.out.println("0. true\t" + con2.getAutoCommit());
24
25 // test commit by checking if a change is visible in another connection
26 try {
27 System.out.print("1. create...");
28 stmt1.executeUpdate("CREATE TABLE table_Test_Cautocommit ( id int )");
29 System.out.println("passed :)");
30 System.out.print("2. select...");
31 rs = stmt2.executeQuery("SELECT * FROM table_Test_Cautocommit");
32 System.out.println("passed :)");
33 } catch (SQLException e) {
34 // this means we failed (table not there perhaps?)
35 System.out.println("FAILED :( " + e.getMessage());
36 System.out.println("ABORTING TEST!!!");
37 con1.close();
38 con2.close();
39 System.exit(-1);
40 }
41
42 // turn off auto commit
43 con1.setAutoCommit(false);
44 con2.setAutoCommit(false);
45
46 // >> false: we just disabled it
47 System.out.println("3. false\t" + con1.getAutoCommit());
48 System.out.println("4. false\t" + con2.getAutoCommit());
49
50 // a change would not be visible now
51 try {
52 System.out.print("5. drop...");
53 stmt2.executeUpdate("DROP TABLE table_Test_Cautocommit");
54 System.out.println("passed :)");
55 System.out.print("6. select...");
56 rs = stmt1.executeQuery("SELECT * FROM table_Test_Cautocommit");
57 System.out.println("passed :)");
58 System.out.print("7. commit...");
59 con2.commit();
60 System.out.println("passed :)");
61 System.out.print("8. select...");
62 rs = stmt1.executeQuery("SELECT * FROM table_Test_Cautocommit");
63 System.out.println("passed :)");
64 System.out.print("9. commit...");
65 con1.commit();
66 System.out.println("passed :)");
67 } catch (SQLException e) {
68 // this means we failed (table not there perhaps?)
69 System.out.println("FAILED :(");
70 System.out.println("ABORTING TEST!!!");
71 }
72
73 if (rs != null) rs.close();
74
75 con1.close();
76 con2.close();
77 }
78 }