Mercurial > hg > monetdb-java
comparison tests/Test_PSsqldata.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 import nl.cwi.monetdb.jdbc.types.*; | |
11 | |
12 public class Test_PSsqldata { | |
13 public static void main(String[] args) throws Exception { | |
14 Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); | |
15 Connection con = DriverManager.getConnection(args[0]); | |
16 Statement stmt = con.createStatement(); | |
17 PreparedStatement pstmt; | |
18 ResultSet rs = null; | |
19 ResultSetMetaData rsmd = null; | |
20 ParameterMetaData pmd = null; | |
21 | |
22 con.setAutoCommit(false); | |
23 // >> false: auto commit should be off now | |
24 System.out.println("0. false\t" + con.getAutoCommit()); | |
25 | |
26 try { | |
27 stmt.executeUpdate("CREATE TABLE table_Test_PSsqldata ( myinet inet, myurl url )"); | |
28 | |
29 pstmt = con.prepareStatement("INSERT INTO table_Test_PSsqldata VALUES (?, ?)"); | |
30 | |
31 pmd = pstmt.getParameterMetaData(); | |
32 System.out.println("1. 2 parameters:\t" + pmd.getParameterCount()); | |
33 for (int col = 1; col <= pmd.getParameterCount(); col++) { | |
34 System.out.println("" + col + "."); | |
35 System.out.println("\ttype " + pmd.getParameterType(col)); | |
36 System.out.println("\ttypename " + pmd.getParameterTypeName(col)); | |
37 System.out.println("\tclassname " + pmd.getParameterClassName(col)); | |
38 } | |
39 | |
40 INET tinet = new INET(); | |
41 URL turl = new URL(); | |
42 | |
43 tinet.fromString("172.5.5.5/24"); | |
44 turl.fromString("http://www.monetdb.org/"); | |
45 pstmt.setObject(1, tinet); | |
46 pstmt.setObject(2, turl); | |
47 pstmt.execute(); | |
48 | |
49 tinet.setNetmaskBits(16); | |
50 pstmt.execute(); | |
51 | |
52 rs = stmt.executeQuery("SELECT * FROM table_Test_PSsqldata"); | |
53 rsmd = rs.getMetaData(); | |
54 | |
55 for (int i = 1; rs.next(); i++) { | |
56 for (int col = 1; col <= rsmd.getColumnCount(); col++) { | |
57 Object x = rs.getObject(col); | |
58 if (x == null) { | |
59 System.out.println("" + i + ".\t<null>"); | |
60 } else { | |
61 System.out.println("" + i + ".\t" + x.toString()); | |
62 if (x instanceof INET) { | |
63 INET inet = (INET)x; | |
64 System.out.println("\t" + inet.getAddress() + "/" + inet.getNetmaskBits()); | |
65 System.out.println("\t" + inet.getInetAddress().toString()); | |
66 } else if (x instanceof URL) { | |
67 URL url = (URL)x; | |
68 System.out.println("\t" + url.getURL().toString()); | |
69 } | |
70 } | |
71 } | |
72 } | |
73 } catch (SQLException e) { | |
74 System.out.println("failed :( "+ e.getMessage()); | |
75 System.out.println("ABORTING TEST!!!"); | |
76 } | |
77 | |
78 con.rollback(); | |
79 con.close(); | |
80 } | |
81 } |