Mercurial > hg > monetdb-java
annotate tests/BugSetQueryTimeout_Bug_3357.java @ 350:54137aeb1f92
Update Copyright year.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 02 Jan 2020 14:42:27 +0100 (2020-01-02) |
parents | d4baf8a4b43a |
children | f523727db392 |
rev | line source |
---|---|
14
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
1 /* |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
5 * |
350
54137aeb1f92
Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2020 MonetDB B.V. |
14
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
7 */ |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
8 |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
9 import java.sql.*; |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
10 |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
11 public class BugSetQueryTimeout_Bug_3357 { |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
12 public static void main(String[] args) throws Exception { |
27
04fbf3655452
Disable Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); code
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
14
diff
changeset
|
13 // Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); // not needed anymore for self registering JDBC drivers |
14
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
14 Connection con = DriverManager.getConnection(args[0]); |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
15 Statement st = con.createStatement(); |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
16 try { |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
17 System.out.println("QueryTimeout = " + st.getQueryTimeout()); |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
18 |
249
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
19 testTimeout(st, 123); |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
20 testTimeout(st, 123); |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
21 testTimeout(st, 2134567890); |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
22 testTimeout(st, 0); |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
23 testTimeout(st, 0); |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
24 testTimeout(st, -1); // to generate an SQLException as negative timeouts are invalid |
14
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
25 } catch (SQLException se) { |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
26 System.out.println("setQueryTimeout(timeout_value) throws: " + se); |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
27 } finally { |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
28 st.close(); |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
29 } |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
30 con.close(); |
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
31 } |
249
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
32 |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
33 private static void testTimeout(Statement st, int secs) throws SQLException { |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
34 st.setQueryTimeout(secs); |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
35 // as the call to set the timeout is delayed till a statement is executed, issue a select statment |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
36 ResultSet rs = st.executeQuery("SELECT " + secs); |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
37 if (rs != null) |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
38 rs.close(); |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
39 System.out.println("QueryTimeout = " + st.getQueryTimeout()); |
46385d8ff8c9
Improve the implementation of Statement methods getQueryTimeout() and setQueryTimeout().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
40 } |
14
3fa949cbc783
Implemented Statement methods: getQueryTimeout() and setQueryTimeout(int seconds).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff
changeset
|
41 } |