001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.lang.bug5054
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.lang;
023:
024: import java.sql.Connection;
025: import java.sql.ResultSet;
026: import java.sql.Statement;
027: import java.sql.SQLException;
028:
029: import org.apache.derby.tools.ij;
030: import org.apache.derby.tools.JDBCDisplayUtil;
031:
032: /**
033: * Where current of cursorname and case sensitivity
034: */
035: public class bug5054 {
036:
037: public static void main(String args[]) {
038: try {
039: /* Load the JDBC Driver class */
040: // use the ij utility to read the property file and
041: // make the initial connection.
042: ij.getPropertyArg(args);
043: Connection conn = ij.startJBMS();
044:
045: createTables(conn);
046: doUpdates(conn);
047: dumpResult(conn);
048: cleanUp(conn);
049: conn.close();
050: } catch (Exception e) {
051: System.out.println("FAIL -- unexpected exception " + e);
052: JDBCDisplayUtil.ShowException(System.out, e);
053: e.printStackTrace();
054: }
055: }
056:
057: private static void createTables(Connection conn)
058: throws SQLException {
059: Statement stmt = conn.createStatement();
060: try {
061: stmt.executeUpdate("DROP TABLE T1");
062: } catch (Exception e) {
063: }
064:
065: System.out.print("Creating tables...");
066: stmt.executeUpdate("CREATE TABLE T1 (a integer, b integer)");
067: stmt.executeUpdate("INSERT INTO T1 VALUES(1, 1)");
068: stmt.executeUpdate("INSERT INTO T1 VALUES(2, 2)");
069: System.out.println("done.");
070:
071: stmt.close();
072: }
073:
074: private static void cleanUp(Connection conn) throws SQLException {
075: Statement stmt = conn.createStatement();
076: try {
077: stmt.executeUpdate("DROP TABLE T1");
078: } catch (Exception e) {
079: }
080: stmt.close();
081: }
082:
083: private static void doUpdates(Connection conn) throws SQLException {
084: int rc;
085: conn.setAutoCommit(false);
086: Statement stmt1 = conn.createStatement();
087: stmt1.setCursorName("aBc");
088: ResultSet rs = stmt1
089: .executeQuery("select * from t1 for update");
090: System.out.println("cursor name is " + rs.getCursorName());
091: rs.next();
092:
093: Statement stmt2 = conn.createStatement();
094: stmt2.execute("update t1 set b=11 where current of \""
095: + rs.getCursorName() + "\"");
096:
097: conn.commit();
098: stmt1.close();
099: stmt2.close();
100: conn.setAutoCommit(true);
101: }
102:
103: private static void dumpResult(Connection conn) throws SQLException {
104: Statement stmt = conn.createStatement();
105: ResultSet rs = stmt.executeQuery("SELECT * FROM T1");
106: System.out.println("T1 contents:");
107: System.out.println("First row should have a b value of 11");
108: while (rs.next()) {
109: System.out.println(rs.getInt(1) + " " + rs.getInt(2));
110: }
111: rs.close();
112: }
113:
114: }
|