1 21 22 package org.apache.derbyTesting.functionTests.tests.jdbcapi; 23 24 import java.sql.Array ; 25 import java.sql.Connection ; 26 import java.sql.ResultSet ; 27 import java.sql.SQLException ; 28 import java.sql.Statement ; 29 30 import org.apache.derby.tools.ij; 31 32 36 37 public class resultsetJdbc30 { 38 public static void main(String [] args) { 39 Connection con; 40 ResultSet rs; 41 Statement stmt; 42 String [] columnNames = {"i", "s", "r", "d", "dt", "t", "ts", "c", "v", "tn", "dc"}; 43 44 System.out.println("Test resultsetJdbc30 starting"); 45 46 try 47 { 48 ij.getPropertyArg(args); 51 con = ij.startJBMS(); 52 53 stmt = con.createStatement(); 54 55 stmt.execute("create table t (i int, s smallint, r real, "+ 57 "d double precision, dt date, t time, ts timestamp, "+ 58 "c char(10), v varchar(40) not null, dc dec(10,2))"); 59 stmt.execute("insert into t values(1,2,3.3,4.4,date('1990-05-05'),"+ 60 "time('12:06:06'),timestamp('1990-07-07 07:07:07.07'),"+ 61 "'eight','nine', 11.1)"); 62 63 rs = stmt.executeQuery("select * from t"); 64 rs.next(); 65 66 try { 68 System.out.println(); 69 System.out.println("trying rs.getURL(int) :"); 70 rs.getURL(8); 71 System.out.println("Shouldn't reach here. Method not implemented yet."); 72 } catch (SQLException ex) { 73 System.out.println("Expected : " + ex.getMessage()); 74 } 75 76 try { 77 System.out.println(); 78 System.out.println("trying rs.getURL(String) :"); 79 rs.getURL("c"); 80 System.out.println("Shouldn't reach here. Method not implemented yet."); 81 } catch (SQLException ex) { 82 System.out.println("Expected : " + ex.getMessage()); 83 } 84 85 try { 86 System.out.println(); 87 System.out.println("trying rs.updateRef(int, Ref) :"); 88 rs.updateRef(8,null); 89 System.out.println("Shouldn't reach here. Method not implemented yet."); 90 } catch (NoSuchMethodError nsme) { 91 System.out.println("ResultSet.updateRef not present - correct for JSR169"); 92 } 93 catch (SQLException ex) { 94 System.out.println("Expected : " + ex.getMessage()); 95 } 96 97 try { 98 System.out.println(); 99 System.out.println("trying rs.updateRef(String, Ref) :"); 100 rs.updateRef("c",null); 101 System.out.println("Shouldn't reach here. Method not implemented yet."); 102 } catch (NoSuchMethodError nsme) { 103 System.out.println("ResultSet.updateRef not present - correct for JSR169"); 104 } catch (SQLException ex) { 105 System.out.println("Expected : " + ex.getMessage()); 106 } 107 108 try { 109 System.out.println(); 110 System.out.println("trying rs.updateBlob(int, Blob) :"); 111 rs.updateBlob(8,null); 112 System.out.println("Shouldn't reach here because method is being invoked on a read only resultset"); 113 } catch (SQLException ex) { 114 System.out.println("Expected : " + ex.getMessage()); 115 } 116 117 try { 118 System.out.println(); 119 System.out.println("trying rs.updateBlob(String, Blob) :"); 120 rs.updateBlob("c",null); 121 System.out.println("Shouldn't reach here because method is being invoked on a read only resultset"); 122 } catch (SQLException ex) { 123 System.out.println("Expected : " + ex.getMessage()); 124 } 125 126 try { 127 System.out.println(); 128 System.out.println("trying rs.updateClob(int, Clob) :"); 129 rs.updateClob(8,null); 130 System.out.println("Shouldn't reach here because method is being invoked on a read only resultset"); 131 } catch (SQLException ex) { 132 System.out.println("Expected : " + ex.getMessage()); 133 } 134 135 try { 136 System.out.println(); 137 System.out.println("trying rs.updateClob(String, Clob) :"); 138 rs.updateClob("c",null); 139 System.out.println("Shouldn't reach here because method is being invoked on a read only resultset"); 140 } catch (SQLException ex) { 141 System.out.println("Expected : " + ex.getMessage()); 142 } 143 144 try { 145 System.out.println(); 146 System.out.println("trying rs.updateArray(int, Array) :"); 147 rs.updateArray(8,null); 148 System.out.println("Shouldn't reach here. Method not implemented yet."); 149 } catch (NoSuchMethodError nsme) { 150 System.out.println("ResultSet.updateArray not present - correct for JSR169"); 151 } catch (SQLException ex) { 152 System.out.println("Expected : " + ex.getMessage()); 153 } 154 155 try { 156 System.out.println(); 157 System.out.println("trying rs.updateArray(String, Array) :"); 158 rs.updateArray("c",null); 159 System.out.println("Shouldn't reach here. Method not implemented yet."); 160 } catch (NoSuchMethodError nsme) { 161 System.out.println("ResultSet.updateArray not present - correct for JSR169"); 162 }catch (SQLException ex) { 163 System.out.println("Expected : " + ex.getMessage()); 164 } 165 166 rs.close(); 167 stmt.close(); 168 169 con.setAutoCommit(true); 174 175 stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 178 ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); 179 180 rs = stmt.executeQuery("select * from t"); 181 rs.next(); 182 183 checkForCloseOnException(rs, true); 184 185 rs.close(); 186 stmt.close(); 187 188 stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 191 ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT); 192 193 rs = stmt.executeQuery("select * from t"); 194 rs.next(); 195 196 checkForCloseOnException(rs, false); 197 198 rs.close(); 199 stmt.close(); 200 con.close(); 201 202 } 203 catch (SQLException e) { 204 dumpSQLExceptions(e); 205 e.printStackTrace(); 206 } 207 catch (Throwable e) { 208 System.out.println("FAIL -- unexpected exception: "+e); 209 e.printStackTrace(); 210 } 211 212 System.out.println("Test resultsetJdbc30 finished"); 213 } 214 215 static private void checkForCloseOnException(ResultSet rs, boolean holdable) 216 throws Exception { 217 try { 218 rs.updateBlob("c",null); 219 throw new Exception ("rs.updateBlob() on a read-only result set" + 220 "should not have succeeded"); 221 } catch (SQLException ex) { 222 } 223 224 try { 225 rs.beforeFirst(); 226 String holdableStr = holdable ? "holdable" : "non-holdable"; 227 System.out.println(holdableStr + " result set was not closed on exception"); 228 } 229 catch ( SQLException ex) { 230 String state = ex.getSQLState(); 231 if ( state.equals("XCL16")) 232 { 233 System.out.println("Holdable result set was closed on exception"); 234 } 235 else 236 { 237 throw ex; 238 } 239 } 240 241 } 242 243 static private void dumpSQLExceptions (SQLException se) { 244 System.out.println("FAIL -- unexpected exception"); 245 while (se != null) { 246 System.out.println("SQLSTATE("+se.getSQLState()+"): "+se); 247 se = se.getNextException(); 248 } 249 } 250 251 } 252 | Popular Tags |