Mercurial > hg > monetdb-java
comparison tests/Test_PStimedate.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_PStimedate { | |
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 PreparedStatement pstmt; | |
17 ResultSet rs = null; | |
18 //DatabaseMetaData dbmd = con.getMetaData(); | |
19 | |
20 con.setAutoCommit(false); | |
21 // >> false: auto commit was just switched off | |
22 System.out.println("0. false\t" + con.getAutoCommit()); | |
23 | |
24 try { | |
25 stmt.executeUpdate("CREATE TABLE table_Test_PStimedate (t time, ts timestamp, d date)"); | |
26 } catch (SQLException e) { | |
27 System.out.println(e); | |
28 System.out.println("Creation of test table failed! :("); | |
29 System.out.println("ABORTING TEST!!!"); | |
30 System.exit(-1); | |
31 } | |
32 | |
33 try { | |
34 pstmt = con.prepareStatement("INSERT INTO table_Test_PStimedate VALUES (?, ?, ?)"); | |
35 System.out.print("1. empty call..."); | |
36 try { | |
37 // should fail (no arguments given) | |
38 pstmt.execute(); | |
39 System.out.println(" PASSED :("); | |
40 System.out.println("ABORTING TEST!!!"); | |
41 System.exit(-1); | |
42 } catch (SQLException e) { | |
43 System.out.println(" failed :)"); | |
44 } | |
45 | |
46 System.out.print("2. inserting a record..."); | |
47 java.util.Date d = new java.util.Date(); | |
48 pstmt.setTime(1, new java.sql.Time(d.getTime())); | |
49 pstmt.setTimestamp(2, new java.sql.Timestamp(d.getTime())); | |
50 pstmt.setDate(3, new java.sql.Date(d.getTime())); | |
51 | |
52 pstmt.executeUpdate(); | |
53 System.out.println(" passed :)"); | |
54 System.out.print("3. closing PreparedStatement..."); | |
55 pstmt.close(); | |
56 System.out.println(" passed :)"); | |
57 | |
58 System.out.print("4. selecting record..."); | |
59 pstmt = con.prepareStatement("SELECT * FROM table_Test_PStimedate"); | |
60 rs = pstmt.executeQuery(); | |
61 System.out.println(" passed :)"); | |
62 | |
63 while (rs.next()) { | |
64 for (int j = 1; j <= 3; j++) { | |
65 System.out.print((j + 4) + ". retrieving..."); | |
66 java.util.Date x = (java.util.Date)(rs.getObject(j)); | |
67 boolean matches = false; | |
68 if (x instanceof Time) { | |
69 System.out.print(" (Time)"); | |
70 matches = (new Time(d.getTime())).toString().equals(x.toString()); | |
71 } else if (x instanceof Date) { | |
72 System.out.print(" (Date)"); | |
73 matches = (new Date(d.getTime())).toString().equals(x.toString()); | |
74 } else if (x instanceof Timestamp) { | |
75 System.out.print(" (Timestamp)"); | |
76 matches = (new Timestamp(d.getTime())).toString().equals(x.toString()); | |
77 } | |
78 if (matches) { | |
79 System.out.println(" passed :)"); | |
80 } else { | |
81 System.out.println(" FAILED :( (" + x + " is not " + d + ")"); | |
82 } | |
83 } | |
84 } | |
85 | |
86 con.rollback(); | |
87 } catch (SQLException e) { | |
88 System.out.println("FAILED :( "+ e.getMessage()); | |
89 System.out.println("ABORTING TEST!!!"); | |
90 } | |
91 | |
92 con.close(); | |
93 } | |
94 } |