Mercurial > hg > monetdb-java
comparison tests/Test_PStypes.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_PStypes { | |
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( | |
26 "CREATE TABLE htmtest (" + | |
27 " htmid bigint NOT NULL," + | |
28 " ra double ," + | |
29 " decl double ," + | |
30 " dra double ," + | |
31 " ddecl double ," + | |
32 " flux double ," + | |
33 " dflux double ," + | |
34 " freq double ," + | |
35 " bw double ," + | |
36 " type decimal(1,0)," + | |
37 " imageurl varchar(100)," + | |
38 " comment varchar(100)," + | |
39 " CONSTRAINT htmtest_htmid_pkey PRIMARY KEY (htmid)" + | |
40 ")" | |
41 ); | |
42 // index is not used, but the original bug had it too | |
43 stmt.executeUpdate("CREATE INDEX htmid ON htmtest (htmid)"); | |
44 } catch (SQLException e) { | |
45 System.out.println(e); | |
46 System.out.println("Creation of test table failed! :("); | |
47 System.out.println("ABORTING TEST!!!"); | |
48 System.exit(-1); | |
49 } | |
50 | |
51 try { | |
52 pstmt = con.prepareStatement( | |
53 "INSERT INTO HTMTEST (HTMID,RA,DECL,FLUX,COMMENT) VALUES (?,?,?,?,?)" | |
54 ); | |
55 System.out.print("1. inserting a record..."); | |
56 | |
57 pstmt.setLong(1, 1L); | |
58 pstmt.setFloat(2, (float)1.2); | |
59 pstmt.setDouble(3, 2.4); | |
60 pstmt.setDouble(4, 3.2); | |
61 pstmt.setString(5, "vlavbla"); | |
62 pstmt.executeUpdate(); | |
63 | |
64 System.out.println("success :)"); | |
65 | |
66 // try an update like bug #1757923 | |
67 pstmt = con.prepareStatement( | |
68 "UPDATE HTMTEST set COMMENT=?, TYPE=? WHERE HTMID=?" | |
69 ); | |
70 System.out.print("2. updating record..."); | |
71 | |
72 pstmt.setString(1, "some update"); | |
73 pstmt.setObject(2, (float)3.2); | |
74 pstmt.setLong(3, 1L); | |
75 pstmt.executeUpdate(); | |
76 | |
77 System.out.println("success :)"); | |
78 } catch (SQLException e) { | |
79 System.out.println("FAILED :( "+ e.getMessage()); | |
80 System.out.println("ABORTING TEST!!!"); | |
81 } | |
82 | |
83 con.rollback(); | |
84 con.close(); | |
85 } | |
86 } |