Mercurial > hg > monetdb-java
comparison tests/Test_PSmanycon.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 import java.util.*; | |
11 | |
12 public class Test_PSmanycon { | |
13 public static void main(String[] args) throws Exception { | |
14 Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); | |
15 List pss = new ArrayList(100); // Connections go in here | |
16 | |
17 try { | |
18 // spawn a lot of Connections, just for fun... | |
19 int i; | |
20 for (i = 0; i < 50; i++) { | |
21 System.out.print("Establishing Connection " + i + "..."); | |
22 Connection con = DriverManager.getConnection(args[0]); | |
23 System.out.print(" done..."); | |
24 | |
25 // do something with the connection to test if it works | |
26 PreparedStatement pstmt = con.prepareStatement("select " + i); | |
27 System.out.println(" alive"); | |
28 | |
29 pss.add(pstmt); | |
30 } | |
31 | |
32 // now try to nicely execute them | |
33 i = 0; | |
34 for (Iterator it = pss.iterator(); it.hasNext(); i++) { | |
35 PreparedStatement pstmt = (PreparedStatement)(it.next()); | |
36 | |
37 // see if the connection still works | |
38 System.out.print("Executing PreparedStatement " + i + "..."); | |
39 if (!pstmt.execute()) | |
40 throw new Exception("should have seen a ResultSet!"); | |
41 | |
42 ResultSet rs = pstmt.getResultSet(); | |
43 if (!rs.next()) | |
44 throw new Exception("ResultSet is empty"); | |
45 System.out.print(" result: " + rs.getString(1)); | |
46 pstmt.getConnection().close(); | |
47 System.out.println(", done"); | |
48 | |
49 if ((i + 1) % 23 == 0) { | |
50 // inject a failed transaction | |
51 Connection con = DriverManager.getConnection(args[0]); | |
52 Statement stmt = con.createStatement(); | |
53 try { | |
54 int affrows = stmt.executeUpdate("update foo where bar is wrong"); | |
55 System.out.println("oops, faulty statement just got through :("); | |
56 } catch (SQLException e) { | |
57 System.out.println("Forced transaction failure"); | |
58 } | |
59 } | |
60 } | |
61 } catch (SQLException e) { | |
62 System.out.println("FAILED! " + e.getMessage()); | |
63 } | |
64 } | |
65 } |