| 1 21 package org.apache.derbyTesting.functionTests.tests.jdbcapi; 22 23 24 import java.sql.*; 25 26 import org.apache.derby.tools.ij; 27 import org.apache.derby.tools.JDBCDisplayUtil; 28 29 import org.apache.derbyTesting.functionTests.util.TestUtil; 30 31 public class rsgetXXXcolumnNames { 32 33 public static void main(String [] args) { 34 test1(args); 35 } 36 37 public static void test1(String []args) { 38 Connection con; 39 ResultSet rs; 40 Statement stmt = null; 41 PreparedStatement stmt1 = null; 42 43 System.out.println("Test rsgetXXXcolumnNames starting"); 44 45 try 46 { 47 ij.getPropertyArg(args); 50 con = ij.startJBMS(); 51 52 53 stmt = con.createStatement(); 54 55 String [] testObjects = {"table caseiscol"}; 57 TestUtil.cleanUpTest(stmt, testObjects); 58 59 con.setAutoCommit(false); 60 61 stmt.executeUpdate("create table caseiscol(COL1 int ,\"col1\" int)"); 63 64 con.commit(); 65 66 stmt.executeUpdate("insert into caseiscol values (1,346)"); 67 68 con.commit(); 69 70 stmt1 = con.prepareStatement("select COL1, \"col1\" from caseiscol FOR UPDATE",ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); 72 rs = stmt1.executeQuery(); 73 74 System.out.println("Before updation..."); 76 while(rs.next()) { 77 System.out.println("ResultSet is: "+rs.getObject(1)); 78 System.out.println("ResultSet is: "+rs.getObject(2)); 79 } 80 rs.close(); 81 rs = stmt1.executeQuery(); 82 while(rs.next()) { 83 rs.updateInt("col1",100); 86 rs.updateInt("COL1",900); 87 rs.updateRow(); 88 } 89 rs.close(); 90 91 System.out.println("After update..."); 92 rs = stmt1.executeQuery(); 93 94 while(rs.next()) { 96 System.out.println("Column Number 1: "+rs.getInt(1)); 97 System.out.println("Column Number 2: "+rs.getInt(2)); 98 } 99 rs.close(); 100 rs = stmt1.executeQuery(); 101 while(rs.next()) { 102 System.out.println("Col COL1: "+rs.getInt("COL1")); 104 System.out.println("Col col1: "+rs.getInt("col1")); 105 } 106 rs.close(); 107 } catch(SQLException sqle) { 108 dumpSQLExceptions(sqle); 109 sqle.printStackTrace(); 110 } catch(Throwable e) { 111 System.out.println("FAIL -- unexpected exception: "+e.getMessage()); 112 e.printStackTrace(); 113 114 } 115 } 116 117 static private void dumpSQLExceptions (SQLException se) { 118 System.out.println("FAIL -- unexpected exception"); 119 while (se != null) { 120 System.out.println("SQLSTATE("+se.getSQLState()+"): "+se.getMessage()); 121 se = se.getNextException(); 122 } 123 } 124 } 125 | Popular Tags |