Mercurial > hg > monetdb-java
comparison tests/Test_PSmetadata.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_PSmetadata { | |
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 ResultSetMetaData rsmd = null; | |
19 ParameterMetaData pmd = null; | |
20 | |
21 con.setAutoCommit(false); | |
22 // >> false: auto commit should be off now | |
23 System.out.println("0. false\t" + con.getAutoCommit()); | |
24 | |
25 try { | |
26 stmt.executeUpdate("CREATE TABLE table_Test_PSmetadata ( myint int, mydouble double, mybool boolean, myvarchar varchar(15), myclob clob )"); | |
27 | |
28 // all NULLs | |
29 stmt.executeUpdate("INSERT INTO table_Test_PSmetadata VALUES (NULL, NULL, NULL, NULL, NULL)"); | |
30 // all filled in | |
31 stmt.executeUpdate("INSERT INTO table_Test_PSmetadata VALUES (2 , 3.0, true, 'A string', 'bla bla bla')"); | |
32 | |
33 pstmt = con.prepareStatement("SELECT CASE WHEN myint IS NULL THEN 0 ELSE 1 END AS intnull, * FROM table_Test_PSmetadata WHERE myint = ?"); | |
34 | |
35 rsmd = pstmt.getMetaData(); | |
36 | |
37 System.out.println("0. 6 columns:\t" + rsmd.getColumnCount()); | |
38 for (int col = 1; col <= rsmd.getColumnCount(); col++) { | |
39 System.out.println("" + col + ".\t" + rsmd.getCatalogName(col)); | |
40 System.out.println("\tclassname " + rsmd.getColumnClassName(col)); | |
41 System.out.println("\tdisplaysize " + rsmd.getColumnDisplaySize(col)); | |
42 System.out.println("\tlabel " + rsmd.getColumnLabel(col)); | |
43 System.out.println("\tname " + rsmd.getColumnName(col)); | |
44 System.out.println("\ttype " + rsmd.getColumnType(col)); | |
45 System.out.println("\ttypename " + rsmd.getColumnTypeName(col)); | |
46 System.out.println("\tprecision " + rsmd.getPrecision(col)); | |
47 System.out.println("\tscale " + rsmd.getScale(col)); | |
48 System.out.println("\tschemaname " + rsmd.getSchemaName(col)); | |
49 System.out.println("\ttablename " + rsmd.getTableName(col)); | |
50 System.out.println("\tautoincrement " + rsmd.isAutoIncrement(col)); | |
51 System.out.println("\tcasesensitive " + rsmd.isCaseSensitive(col)); | |
52 System.out.println("\tcurrency " + rsmd.isCurrency(col)); | |
53 System.out.println("\tdefwritable " + rsmd.isDefinitelyWritable(col)); | |
54 System.out.println("\tnullable " + rsmd.isNullable(col)); | |
55 System.out.println("\treadonly " + rsmd.isReadOnly(col)); | |
56 System.out.println("\tsearchable " + rsmd.isSearchable(col)); | |
57 System.out.println("\tsigned " + rsmd.isSigned(col)); | |
58 System.out.println("\twritable " + rsmd.isWritable(col)); | |
59 } | |
60 | |
61 pmd = pstmt.getParameterMetaData(); | |
62 System.out.println("1. 1 parameter:\t" + pmd.getParameterCount()); | |
63 for (int col = 1; col <= pmd.getParameterCount(); col++) { | |
64 System.out.println("" + col + "."); | |
65 System.out.println("\tnullable " + pmd.isNullable(col)); | |
66 System.out.println("\tsigned " + pmd.isSigned(col)); | |
67 System.out.println("\tprecision " + pmd.getPrecision(col)); | |
68 System.out.println("\tscale " + pmd.getScale(col)); | |
69 System.out.println("\ttype " + pmd.getParameterType(col)); | |
70 System.out.println("\ttypename " + pmd.getParameterTypeName(col)); | |
71 System.out.println("\tclassname " + pmd.getParameterClassName(col)); | |
72 System.out.println("\tmode " + pmd.getParameterMode(col)); | |
73 } | |
74 } catch (SQLException e) { | |
75 System.out.println("failed :( "+ e.getMessage()); | |
76 System.out.println("ABORTING TEST!!!"); | |
77 } | |
78 | |
79 con.rollback(); | |
80 con.close(); | |
81 } | |
82 | |
83 private static String isInstance(Object obj, String type) { | |
84 if (obj == null) | |
85 return("(null)"); | |
86 try { | |
87 Class c = Class.forName(type); | |
88 if (c.isInstance(obj)) { | |
89 return(obj.getClass().getName() + " is an instance of " + type); | |
90 } else { | |
91 return(obj.getClass().getName() + " is NOT an instance of " + type); | |
92 } | |
93 } catch (ClassNotFoundException e) { | |
94 return("No such class: " + type); | |
95 } | |
96 } | |
97 } |