1 21 22 package org.apache.derbyTesting.functionTests.tests.jdbcapi; 23 24 import java.sql.Connection ; 25 import java.sql.DriverManager ; 26 import java.sql.DatabaseMetaData ; 27 import java.sql.ResultSetMetaData ; 28 import java.sql.PreparedStatement ; 29 import java.sql.Statement ; 30 import java.sql.ResultSet ; 31 import java.sql.SQLException ; 32 import java.sql.Types ; 33 34 import org.apache.derby.tools.ij; 35 import org.apache.derbyTesting.functionTests.util.TestUtil; 36 import org.apache.derbyTesting.functionTests.util.JDBCTestDisplayUtil; 37 38 45 46 public class nullSQLText { 47 public static void main(String [] args) { 48 Connection con; 49 PreparedStatement ps; 50 Statement s; 51 String nullString = null; 52 53 System.out.println("Test nullSQLText starting"); 54 55 try 56 { 57 ij.getPropertyArg(args); 60 con = ij.startJBMS(); 61 con.setAutoCommit(true); s = con.createStatement(); 63 64 try { 66 s.execute("drop table t1"); 67 } catch (SQLException se) {} 68 try { 69 s.execute("drop procedure za"); 70 } catch (SQLException se) {} 71 72 try 73 { 74 System.out.println("Test prepareStatement with null argument"); 76 ps = con.prepareStatement(nullString); 77 } 78 catch (SQLException e) { 79 System.out.println("FAIL -- expected exception"); 80 dumpSQLExceptions(e); 81 } 82 try 83 { 84 System.out.println("Test execute with null argument"); 86 s.execute(nullString); 87 } 88 catch (SQLException e) { 89 System.out.println("FAIL -- expected exception"); 90 dumpSQLExceptions(e); 91 } 92 try 93 { 94 System.out.println("Test executeQuery with null argument"); 96 s.executeQuery(nullString); 97 } 98 catch (SQLException e) { 99 System.out.println("FAIL -- expected exception"); 100 dumpSQLExceptions(e); 101 } 102 try 103 { 104 System.out.println("Test executeUpdate with null argument"); 106 s.executeUpdate(nullString); 107 } 108 catch (SQLException e) { 109 System.out.println("FAIL -- expected exception"); 110 dumpSQLExceptions(e); 111 } 112 113 derby522(s); 115 116 con.close(); 117 } 118 catch (SQLException e) { 119 dumpSQLExceptions(e); 120 e.printStackTrace(System.out); 121 } 122 catch (Throwable e) { 123 System.out.println("FAIL -- unexpected exception:"); 124 e.printStackTrace(System.out); 125 } 126 127 System.out.println("Test nullSQLText finished"); 128 } 129 static private void dumpSQLExceptions (SQLException se) { 130 while (se != null) { 131 JDBCTestDisplayUtil.ShowCommonSQLException(System.out, se); 132 se = se.getNextException(); 133 } 134 } 135 136 137 148 private static void derby522(Statement st) throws Exception 149 { 150 System.out.println("Starting test for DERBY-522."); 151 152 st.execute("create table t1 (i int)"); 153 st.execute("insert into t1 values 1, 2, 3, 4, 5, 6, 7"); 154 st.execute("create procedure za() language java external name " + 155 "'org.apache.derbyTesting.functionTests.util.ProcedureTest.zeroArg'" + 156 " parameter style java"); 157 158 testCommentStmt(st, " --", true); 160 testCommentStmt(st, " -- ", true); 161 testCommentStmt(st, " -- This is a comment \n --", true); 162 testCommentStmt( 163 st, 164 " -- This is a comment\n --And another\n -- Andonemore", 165 true); 166 167 testCommentStmt(st, " --\nvalues 2, 4, 8", TestUtil.isJCCFramework()); 171 testCommentStmt( 172 st, 173 " -- This is \n -- \n --3 comments\nvalues 8", 174 TestUtil.isJCCFramework()); 175 testCommentStmt( 176 st, 177 " -- This is a comment\n --And another\n -- Andonemore\nvalues (2,3)", 178 TestUtil.isJCCFramework()); 179 testCommentStmt(st, 180 " -- This is a comment\n select i from t1", 181 TestUtil.isJCCFramework()); 182 testCommentStmt(st, 183 " --singleword\n insert into t1 values (8)", 184 TestUtil.isJCCFramework()); 185 testCommentStmt(st, 186 " --singleword\ncall za()", 187 TestUtil.isJCCFramework()); 188 testCommentStmt(st, 189 " -- leading comment\n(\nvalues 4, 8)", 190 TestUtil.isJCCFramework()); 191 testCommentStmt(st, 192 " -- leading comment\n\n(\n\n\rvalues 4, 8)", 193 TestUtil.isJCCFramework()); 194 195 testCommentStmt(st, "select i from t1 -- This is a comment", false); 201 testCommentStmt(st, "select i from t1\n -- This is a comment", false); 202 testCommentStmt(st, "values 8, 4, 2\n --", false); 203 testCommentStmt(st, "values 8, 4,\n -- middle comment\n2\n -- end", false); 204 testCommentStmt(st, "values 8, 4,\n -- middle comment\n2\n -- end\n", false); 205 206 try { 208 st.execute("drop table t1"); 209 } catch (SQLException se) {} 210 try { 211 st.execute("drop procedure za"); 212 } catch (SQLException se) {} 213 214 st.close(); 215 System.out.println("DERBY-522 test completed."); 216 } 217 218 221 private static void testCommentStmt(Statement st, String sql, 222 boolean expectError) throws SQLException 223 { 224 225 try { 226 227 System.out.println("[ Test Statement ]:\n" + sql); 228 st.execute(sql); 229 System.out.print("[ Results ]: "); 230 ResultSet rs = st.getResultSet(); 231 if (rs != null) { 232 while (rs.next()) 233 System.out.print(" " + rs.getInt(1)); 234 System.out.println(); 235 } 236 else 237 System.out.println("(NO RESULT SET)"); 238 239 } catch (SQLException se) { 240 241 if (expectError) 242 System.out.print("[ EXPECTED ERROR ]: "); 243 else 244 System.out.print("[ FAILED ]: "); 245 dumpSQLExceptions(se); 246 247 } 248 249 } 250 } 251 | Popular Tags |