KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > jdbcapi > resultsetJdbc20


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.resultsetJdbc20
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
23
24 import java.sql.Connection JavaDoc;
25 import java.sql.DriverManager JavaDoc;
26 import java.sql.ResultSetMetaData JavaDoc;
27 import java.sql.ResultSet JavaDoc;
28 import java.sql.Statement JavaDoc;
29 import java.sql.SQLException JavaDoc;
30 import java.sql.Types JavaDoc;
31
32 import org.apache.derby.tools.ij;
33 import org.apache.derby.tools.JDBCDisplayUtil;
34
35 import org.apache.derbyTesting.functionTests.util.TestUtil;
36
37 /**
38  * Test of additional methods in JDBC2.0 result set meta-data.
39  * This program simply calls each of the additional result set meta-data
40  * methods, one by one, and prints the results.
41  *
42  */

43
44 public class resultsetJdbc20 {
45     private static String JavaDoc[] testObjects = { "TABLE T"};
46     public static void main(String JavaDoc[] args) {
47         Connection JavaDoc con;
48         ResultSetMetaData JavaDoc met;
49         ResultSet JavaDoc rs;
50         Statement JavaDoc stmt;
51         
52         String JavaDoc[] columnNames = {"i", "s", "r", "d", "dt", "t", "ts", "c", "v", "dc"};
53
54         System.out.println("Test resultsetJdbc20 starting");
55
56         try
57         {
58             // use the ij utility to read the property file and
59
// make the initial connection.
60
ij.getPropertyArg(args);
61             con = ij.startJBMS();
62             stmt = con.createStatement();
63             // first clean up
64
TestUtil.cleanUpTest(stmt, testObjects);
65
66       //create a table, insert a row, do a select from the table,
67
//get the resultset meta data and go through each column in
68
//the selection list and get it's column class name.
69
stmt.execute("create table t (i int, s smallint, r real, "+
70                 "d double precision, dt date, t time, ts timestamp, "+
71                 "c char(10), v varchar(40) not null, dc dec(10,2))");
72             stmt.execute("insert into t values(1,2,3.3,4.4,date('1990-05-05'),"+
73                          "time('12:06:06'),timestamp('1990-07-07 07:07:07.07'),"+
74                          "'eight','nine', 10.1)");
75
76             rs = stmt.executeQuery("select * from t");
77             met = rs.getMetaData();
78
79             int colCount;
80             System.out.println("getColumnCount(): "+(colCount=met.getColumnCount()));
81
82             // JDBC columns use 1-based counting
83
for (int i=1;i<=colCount;i++) {
84                 // this test suffers from bug 5775.
85
// this if should be removed if the bug is fixed.
86
if (i==2 && (met.getColumnClassName(i).equals("java.lang.Short")))
87                 {
88                     System.out.println("getColumnName("+i+"): "+met.getColumnName(i));
89                     //System.out.println("getColumnClassName("+i+"): "+met.getColumnClassName(i));
90
System.out.println("FAIL: should be java.lang.Integer - but is java.lang.Short. see beetle 5775");
91                 }
92                 else
93                 {
94                     System.out.println("getColumnName("+i+"): "+met.getColumnName(i));
95                     System.out.println("getColumnClassName("+i+"): "+met.getColumnClassName(i));
96                 }
97             }
98
99             rs.close();
100
101             TestUtil.cleanUpTest(stmt, testObjects);
102             stmt.close();
103             con.close();
104
105         }
106         catch (SQLException JavaDoc e) {
107             dumpSQLExceptions(e);
108             e.printStackTrace();
109         }
110         catch (Throwable JavaDoc e) {
111             System.out.println("FAIL -- unexpected exception: "+e);
112             e.printStackTrace();
113         }
114
115         System.out.println("Test resultsetJdbc20 finished");
116     }
117
118     static private void dumpSQLExceptions (SQLException JavaDoc se) {
119         System.out.println("FAIL -- unexpected exception");
120         while (se != null) {
121             System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
122             se = se.getNextException();
123         }
124     }
125
126 }
127
Popular Tags