Mercurial > hg > monetdb-java
comparison tests/Test_Creplysize.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_Creplysize { | |
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 Statement stmt1 = con1.createStatement(); | |
16 ResultSet rs = null; | |
17 //DatabaseMetaData dbmd = con.getMetaData(); | |
18 | |
19 con1.setAutoCommit(false); | |
20 // >> true: auto commit should be off by now | |
21 System.out.println("0. true\t" + con1.getAutoCommit()); | |
22 | |
23 // test commit by checking if a change is visible in another connection | |
24 try { | |
25 System.out.print("1. create... "); | |
26 stmt1.executeUpdate("CREATE TABLE table_Test_Creplysize ( id int )"); | |
27 System.out.println("passed :)"); | |
28 | |
29 System.out.print("2. populating with 21 records... "); | |
30 for (int i = 0; i < 21; i++) | |
31 stmt1.executeUpdate("INSERT INTO table_Test_Creplysize (id) values (" + (i + 1) + ")"); | |
32 System.out.println("passed :)"); | |
33 | |
34 System.out.print("3. hinting the driver to use fetchsize 10... "); | |
35 stmt1.setFetchSize(10); | |
36 System.out.println("passed :)"); | |
37 | |
38 System.out.print("4. selecting all values... "); | |
39 rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize"); | |
40 int i = 0; | |
41 while (rs.next()) i++; | |
42 rs.close(); | |
43 if (i == 21) { | |
44 System.out.println("passed :)"); | |
45 } else { | |
46 throw new SQLException("got " + i + " records!!!"); | |
47 } | |
48 | |
49 System.out.print("5. resetting driver fetchsize hint... "); | |
50 stmt1.setFetchSize(0); | |
51 System.out.println("passed :)"); | |
52 | |
53 System.out.print("6. instructing the driver to return at max 10 rows... "); | |
54 stmt1.setMaxRows(10); | |
55 System.out.println("passed :)"); | |
56 | |
57 System.out.print("7. selecting all values... "); | |
58 rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize"); | |
59 i = 0; | |
60 while (rs.next()) i++; | |
61 rs.close(); | |
62 if (i == 10) { | |
63 System.out.println("passed :)"); | |
64 } else { | |
65 throw new SQLException("got " + i + " records!!!"); | |
66 } | |
67 | |
68 System.out.print("8. hinting the driver to use fetchsize 5... "); | |
69 stmt1.setFetchSize(5); | |
70 System.out.println("passed :)"); | |
71 | |
72 System.out.print("9. selecting all values... "); | |
73 rs = stmt1.executeQuery("SELECT * FROM table_Test_Creplysize"); | |
74 i = 0; | |
75 while (rs.next()) i++; | |
76 rs.close(); | |
77 if (i == 10) { | |
78 System.out.println("passed :)"); | |
79 } else { | |
80 throw new SQLException("got " + i + " records!!!"); | |
81 } | |
82 } catch (SQLException e) { | |
83 // this means we failed (table not there perhaps?) | |
84 System.out.println("FAILED :( " + e.getMessage()); | |
85 System.out.println("ABORTING TEST!!!"); | |
86 con1.close(); | |
87 System.exit(-1); | |
88 } | |
89 | |
90 con1.close(); | |
91 } | |
92 } |