001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.rsgetXXXcolumnNames
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: package org.apache.derbyTesting.functionTests.tests.jdbcapi;
022:
023: import java.sql.*;
024:
025: import org.apache.derby.tools.ij;
026: import org.apache.derby.tools.JDBCDisplayUtil;
027:
028: import org.apache.derbyTesting.functionTests.util.TestUtil;
029:
030: public class rsgetXXXcolumnNames {
031:
032: public static void main(String[] args) {
033: test1(args);
034: }
035:
036: public static void test1(String[] args) {
037: Connection con;
038: ResultSet rs;
039: Statement stmt = null;
040: PreparedStatement stmt1 = null;
041:
042: System.out.println("Test rsgetXXXcolumnNames starting");
043:
044: try {
045: // use the ij utility to read the property file and
046: // make the initial connection.
047: ij.getPropertyArg(args);
048: con = ij.startJBMS();
049:
050: stmt = con.createStatement();
051:
052: // first cleanup in case we're using useprocess false
053: String[] testObjects = { "table caseiscol" };
054: TestUtil.cleanUpTest(stmt, testObjects);
055:
056: con.setAutoCommit(false);
057:
058: // create a table with two columns, their names differ in they being in different cases.
059: stmt
060: .executeUpdate("create table caseiscol(COL1 int ,\"col1\" int)");
061:
062: con.commit();
063:
064: stmt.executeUpdate("insert into caseiscol values (1,346)");
065:
066: con.commit();
067:
068: // select data from this table for updating
069: stmt1 = con.prepareStatement(
070: "select COL1, \"col1\" from caseiscol FOR UPDATE",
071: ResultSet.TYPE_FORWARD_ONLY,
072: ResultSet.CONCUR_UPDATABLE);
073: rs = stmt1.executeQuery();
074:
075: // Get the data and disply it before updating.
076: System.out.println("Before updation...");
077: while (rs.next()) {
078: System.out.println("ResultSet is: " + rs.getObject(1));
079: System.out.println("ResultSet is: " + rs.getObject(2));
080: }
081: rs.close();
082: rs = stmt1.executeQuery();
083: while (rs.next()) {
084: // Update the two columns with different data.
085: // Since update is case insensitive only the first column should get updated in both cases.
086: rs.updateInt("col1", 100);
087: rs.updateInt("COL1", 900);
088: rs.updateRow();
089: }
090: rs.close();
091:
092: System.out.println("After update...");
093: rs = stmt1.executeQuery();
094:
095: // Display the data after updating. Only the first column should have the updated value.
096: while (rs.next()) {
097: System.out.println("Column Number 1: " + rs.getInt(1));
098: System.out.println("Column Number 2: " + rs.getInt(2));
099: }
100: rs.close();
101: rs = stmt1.executeQuery();
102: while (rs.next()) {
103: // Again checking for case insensitive behaviour here, should display the data in the first column.
104: System.out.println("Col COL1: " + rs.getInt("COL1"));
105: System.out.println("Col col1: " + rs.getInt("col1"));
106: }
107: rs.close();
108: } catch (SQLException sqle) {
109: dumpSQLExceptions(sqle);
110: sqle.printStackTrace();
111: } catch (Throwable e) {
112: System.out.println("FAIL -- unexpected exception: "
113: + e.getMessage());
114: e.printStackTrace();
115:
116: }
117: }
118:
119: static private void dumpSQLExceptions(SQLException se) {
120: System.out.println("FAIL -- unexpected exception");
121: while (se != null) {
122: System.out.println("SQLSTATE(" + se.getSQLState() + "): "
123: + se.getMessage());
124: se = se.getNextException();
125: }
126: }
127: }
|