001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.resultsetJdbc20
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derbyTesting.functionTests.tests.jdbcapi;
023:
024: import java.sql.Connection;
025: import java.sql.DriverManager;
026: import java.sql.ResultSetMetaData;
027: import java.sql.ResultSet;
028: import java.sql.Statement;
029: import java.sql.SQLException;
030: import java.sql.Types;
031:
032: import org.apache.derby.tools.ij;
033: import org.apache.derby.tools.JDBCDisplayUtil;
034:
035: import org.apache.derbyTesting.functionTests.util.TestUtil;
036:
037: /**
038: * Test of additional methods in JDBC2.0 result set meta-data.
039: * This program simply calls each of the additional result set meta-data
040: * methods, one by one, and prints the results.
041: *
042: */
043:
044: public class resultsetJdbc20 {
045: private static String[] testObjects = { "TABLE T" };
046:
047: public static void main(String[] args) {
048: Connection con;
049: ResultSetMetaData met;
050: ResultSet rs;
051: Statement stmt;
052:
053: String[] columnNames = { "i", "s", "r", "d", "dt", "t", "ts",
054: "c", "v", "dc" };
055:
056: System.out.println("Test resultsetJdbc20 starting");
057:
058: try {
059: // use the ij utility to read the property file and
060: // make the initial connection.
061: ij.getPropertyArg(args);
062: con = ij.startJBMS();
063: stmt = con.createStatement();
064: // first clean up
065: TestUtil.cleanUpTest(stmt, testObjects);
066:
067: //create a table, insert a row, do a select from the table,
068: //get the resultset meta data and go through each column in
069: //the selection list and get it's column class name.
070: stmt
071: .execute("create table t (i int, s smallint, r real, "
072: + "d double precision, dt date, t time, ts timestamp, "
073: + "c char(10), v varchar(40) not null, dc dec(10,2))");
074: stmt
075: .execute("insert into t values(1,2,3.3,4.4,date('1990-05-05'),"
076: + "time('12:06:06'),timestamp('1990-07-07 07:07:07.07'),"
077: + "'eight','nine', 10.1)");
078:
079: rs = stmt.executeQuery("select * from t");
080: met = rs.getMetaData();
081:
082: int colCount;
083: System.out.println("getColumnCount(): "
084: + (colCount = met.getColumnCount()));
085:
086: // JDBC columns use 1-based counting
087: for (int i = 1; i <= colCount; i++) {
088: // this test suffers from bug 5775.
089: // this if should be removed if the bug is fixed.
090: if (i == 2
091: && (met.getColumnClassName(i)
092: .equals("java.lang.Short"))) {
093: System.out.println("getColumnName(" + i + "): "
094: + met.getColumnName(i));
095: //System.out.println("getColumnClassName("+i+"): "+met.getColumnClassName(i));
096: System.out
097: .println("FAIL: should be java.lang.Integer - but is java.lang.Short. see beetle 5775");
098: } else {
099: System.out.println("getColumnName(" + i + "): "
100: + met.getColumnName(i));
101: System.out.println("getColumnClassName(" + i
102: + "): " + met.getColumnClassName(i));
103: }
104: }
105:
106: rs.close();
107:
108: TestUtil.cleanUpTest(stmt, testObjects);
109: stmt.close();
110: con.close();
111:
112: } catch (SQLException e) {
113: dumpSQLExceptions(e);
114: e.printStackTrace();
115: } catch (Throwable e) {
116: System.out.println("FAIL -- unexpected exception: " + e);
117: e.printStackTrace();
118: }
119:
120: System.out.println("Test resultsetJdbc20 finished");
121: }
122:
123: static private void dumpSQLExceptions(SQLException se) {
124: System.out.println("FAIL -- unexpected exception");
125: while (se != null) {
126: System.out.println("SQLSTATE(" + se.getSQLState() + "): "
127: + se);
128: se = se.getNextException();
129: }
130: }
131:
132: }
|