comparison tests/Test_Rpositioning.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_Rpositioning {
12 public static void main(String[] args) throws Exception {
13 Class.forName("nl.cwi.monetdb.jdbc.MonetDriver");
14 Connection con = DriverManager.getConnection(args[0]);
15 Statement stmt = con.createStatement();
16 DatabaseMetaData dbmd = con.getMetaData();
17
18 // get a one rowed resultset
19 ResultSet rs = stmt.executeQuery("SELECT 1");
20
21 // >> true: we should be before the first result now
22 System.out.println("1. true\t" + rs.isBeforeFirst());
23 // >> false: we're not at the first result
24 System.out.println("2. false\t" + rs.isFirst());
25 // >> true: there is one result, so we can call next once
26 System.out.println("3. true\t" + rs.next());
27 // >> false: we're not before the first row anymore
28 System.out.println("4. false\t" + rs.isBeforeFirst());
29 // >> true: we're at the first result
30 System.out.println("5. true\t" + rs.isFirst());
31 // >> false: we're on the last row
32 System.out.println("6. false\t" + rs.isAfterLast());
33 // >> true: see above
34 System.out.println("7. true\t" + rs.isLast());
35 // >> false: there is one result, so this is it
36 System.out.println("8. false\t" + rs.next());
37 // >> true: yes, we're at the end
38 System.out.println("9. true\t" + rs.isAfterLast());
39 // >> false: no we're one over it
40 System.out.println("10. false\t" + rs.isLast());
41 // >> false: another try to move on should still fail
42 System.out.println("11. false\t" + rs.next());
43 // >> true: and we should stay positioned after the last
44 System.out.println("12.true\t" + rs.isAfterLast());
45
46 rs.close();
47
48 // try the same with a 'virtual' result set
49 rs = dbmd.getTableTypes();
50
51 // >> true: we should be before the first result now
52 System.out.println("1. true\t" + rs.isBeforeFirst());
53 // >> false: we're not at the first result
54 System.out.println("2. false\t" + rs.isFirst());
55 // >> true: there is one result, so we can call next once
56 System.out.println("3. true\t" + rs.next());
57 // >> false: we're not before the first row anymore
58 System.out.println("4. false\t" + rs.isBeforeFirst());
59 // >> true: we're at the first result
60 System.out.println("5. true\t" + rs.isFirst());
61 // move to last row
62 rs.last();
63 // >> false: we're on the last row
64 System.out.println("6. false\t" + rs.isAfterLast());
65 // >> true: see above
66 System.out.println("7. true\t" + rs.isLast());
67 // >> false: there is one result, so this is it
68 System.out.println("8. false\t" + rs.next());
69 // >> true: yes, we're at the end
70 System.out.println("9. true\t" + rs.isAfterLast());
71 // >> false: no we're one over it
72 System.out.println("10. false\t" + rs.isLast());
73 // >> false: another try to move on should still fail
74 System.out.println("11. false\t" + rs.next());
75 // >> true: and we should stay positioned after the last
76 System.out.println("12. true\t" + rs.isAfterLast());
77
78 rs.close();
79
80 con.close();
81 }
82 }