1 21 22 package org.apache.derbyTesting.functionTests.tests.lang; 23 24 import java.sql.Connection ; 25 import java.sql.ResultSet ; 26 import java.sql.Statement ; 27 import java.sql.SQLException ; 28 29 import org.apache.derby.tools.ij; 30 import org.apache.derby.tools.JDBCDisplayUtil; 31 32 35 public class bug5054 { 36 37 public static void main (String args[]) 38 { 39 try { 40 41 ij.getPropertyArg(args); 44 Connection conn = ij.startJBMS(); 45 46 createTables(conn); 47 doUpdates(conn); 48 dumpResult(conn); 49 cleanUp(conn); 50 conn.close(); 51 } catch (Exception e) { 52 System.out.println("FAIL -- unexpected exception "+e); 53 JDBCDisplayUtil.ShowException(System.out, e); 54 e.printStackTrace(); 55 } 56 } 57 58 private static void createTables(Connection conn) throws SQLException { 59 Statement stmt = conn.createStatement(); 60 try { 61 stmt.executeUpdate( "DROP TABLE T1" ); 62 }catch (Exception e) {} 63 64 System.out.print("Creating tables..."); 65 stmt.executeUpdate( "CREATE TABLE T1 (a integer, b integer)" ); 66 stmt.executeUpdate( "INSERT INTO T1 VALUES(1, 1)" ); 67 stmt.executeUpdate( "INSERT INTO T1 VALUES(2, 2)" ); 68 System.out.println("done."); 69 70 stmt.close(); 71 } 72 73 private static void cleanUp(Connection conn) throws SQLException { 74 Statement stmt = conn.createStatement(); 75 try { 76 stmt.executeUpdate( "DROP TABLE T1" ); 77 }catch (Exception e) {} 78 stmt.close(); 79 } 80 81 private static void doUpdates(Connection conn) throws SQLException 82 { 83 int rc; 84 conn.setAutoCommit(false); 85 Statement stmt1 = conn.createStatement(); 86 stmt1.setCursorName("aBc"); 87 ResultSet rs = stmt1.executeQuery("select * from t1 for update"); 88 System.out.println("cursor name is " + rs.getCursorName()); 89 rs.next(); 90 91 Statement stmt2 = conn.createStatement(); 92 stmt2.execute("update t1 set b=11 where current of \"" + rs.getCursorName() + "\""); 93 94 conn.commit(); 95 stmt1.close(); 96 stmt2.close(); 97 conn.setAutoCommit(true); 98 } 99 100 private static void dumpResult(Connection conn) throws SQLException 101 { 102 Statement stmt = conn.createStatement(); 103 ResultSet rs = stmt.executeQuery( 104 "SELECT * FROM T1" 105 ); 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 } 115 | Popular Tags |