1 30 31 32 package org.hsqldb.test; 33 34 import java.sql.Connection ; 35 import java.sql.DriverManager ; 36 import java.sql.ResultSet ; 37 import java.sql.Statement ; 38 39 public class TestMultipleConnections { 40 41 public TestMultipleConnections() {} 42 43 public static void main(String [] args) throws Exception { 44 45 TestMultipleConnections hs = new TestMultipleConnections(); 47 Connection con1 = hs.createObject(); 48 Connection con2 = hs.createObject(); 49 Connection con3 = hs.createObject(); 50 51 con1.setAutoCommit(false); 52 53 con2.setAutoCommit(false); 55 56 con3.setAutoCommit(false); 58 59 Statement st = con3.createStatement(); 61 62 st.execute("DROP TABLE T IF EXISTS"); 63 st.execute("CREATE TABLE T (I INT)"); 64 st.execute("INSERT INTO T VALUES (2)"); 65 66 ResultSet rs = st.executeQuery("SELECT * FROM T"); 67 68 rs.next(); 69 70 int value = rs.getInt(1); 71 72 con2.commit(); 73 con3.commit(); 74 con1.commit(); 75 76 rs = st.executeQuery("SELECT * FROM T"); 77 78 rs.next(); 79 80 if (value != rs.getInt(1)) { 81 throw new Exception ("value doesn't exist"); 82 } 83 } 84 85 88 protected Connection createObject() { 89 90 try { 91 Class.forName("org.hsqldb.jdbcDriver"); 92 93 return DriverManager.getConnection("jdbc:hsqldb:/hsql/test/test", 94 "sa", ""); 95 } catch (Exception ex) { 96 ex.printStackTrace(); 97 } 98 99 return null; 100 } 101 } 102 | Popular Tags |