📄 stmtclosefuntest.java
字号:
try { ps.cancel(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } if (isDerbyNet) System.out.println("beetle 5524"); try { ps.getWarnings(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } if (isDerbyNet) System.out.println("beetle 5524"); try { ps.clearWarnings(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.setCursorName("ABC"); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.execute("create table tab3(num int)"); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.getResultSet(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.getUpdateCount(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.getMoreResults(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.getResultSetType(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.setFetchDirection(JDBC20Translation.FETCH_FORWARD); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.setFetchSize(100); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.getFetchSize(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.getResultSetConcurrency(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.addBatch(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.clearBatch(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.executeBatch(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } try { ps.getConnection(); System.out.println("Prepared Statement Test failed"); } catch(SQLException e) { } } catch (Throwable e) { System.out.println("FAIL -- unexpected exception:" + e.toString()); e.printStackTrace(System.out); return; } System.out.println("Prepared Statement test end");} private static void test3(Connection conn) { CallableStatement cs; try { System.out.println("Callable Statement test begin"); try { Statement s = conn.createStatement(); s.execute("CREATE PROCEDURE takesString(OUT P1 VARCHAR(40), IN P2 INT) " + "EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams.takesString'" + " NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA"); cs = conn.prepareCall("call takesString(?,?)"); cs.registerOutParameter(1, Types.CHAR); cs.setInt(2, Types.INTEGER); cs.execute(); System.out.println("The result is " + cs.getString(1)); cs.close(); try { cs.setString(1, "ABC"); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.registerOutParameter(1, Types.CHAR); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } s.execute("drop procedure takesString"); s.close(); } catch(SQLException e) { dumpSQLExceptions(e); } //now, testing all the inherited functions cs = conn.prepareCall("create table tab3(a int, b float, c varchar(100))"); cs.execute(); cs.close(); //we test execute() and executeQuery() here cs = conn.prepareCall("select a from tab3"); ResultSet rs = cs.executeQuery(); cs.close(); try { cs.execute(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.executeQuery(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } cs = conn.prepareCall("insert into tab3 values(?, ?, ?)"); /* We create a table, add a row, and close the statement. */ cs.setInt(1, 420); cs.setFloat(2, (float)12.21); cs.setString(3, "China"); cs.executeUpdate(); cs.close(); //now, we begin the test try { cs.setInt(1, 530); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.setFloat(2, (float)3.14); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.setString(3, "HongKong"); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.executeUpdate(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } /* close() is the only method that can be called * after a Statement has been closed, as per * Jon Ellis. */ try { cs.close(); } catch(SQLException e) { System.out.println("Callable Statement Test failed"); } try { cs.clearParameters(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.getMetaData(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.getMaxFieldSize(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.setMaxFieldSize(100); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.getMaxRows(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.setMaxRows(1000); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.setEscapeProcessing(true); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } if (! isDerbyNet) { try { // currently derby only supports returning 0 in this case. int qry_timeout = cs.getQueryTimeout(); if (qry_timeout != 0) System.out.println("Statement Test failed, must return 0."); } catch(SQLException e) { System.out.println("Statement Test failed"); } } try { cs.setQueryTimeout(20); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.cancel(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } if (isDerbyNet) System.out.println("beetle 5524"); try { cs.getWarnings(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } if (isDerbyNet) System.out.println("beetle 5524"); try { cs.clearWarnings(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.setCursorName("ABC"); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.execute("create table tab3(num int)"); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.getResultSet(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.getUpdateCount(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.getMoreResults(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.getResultSetType(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.setFetchDirection(JDBC20Translation.FETCH_FORWARD); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.setFetchSize(100); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.getFetchSize(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.getResultSetConcurrency(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.addBatch(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.clearBatch(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.executeBatch(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } try { cs.getConnection(); System.out.println("Callable Statement Test failed"); } catch(SQLException e) { } } catch (Throwable e) { System.out.println("FAIL -- unexpected exception:" + e.toString()); e.printStackTrace(System.out); return; } System.out.println("Callable Statement test end");} static private void dumpSQLExceptions (SQLException se) { System.out.println("FAIL -- unexpected exception: " + se.toString()); while (se != null) { System.out.print("SQLSTATE("+se.getSQLState()+"):"); se = se.getNextException(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -