就像标题所说的那样,我想知道为什么准备好的语句.isClosed()方法在关闭基础流(使用JDBC)后将返回false。
public void someTest() throws SQLException, InterruptedException {
Connection conn = DBHelper.newConnection();
PreparedStatement statement = conn.prepareCall(CLEANUP_DELETE);
conn.close();
System.out.println(statement.isClosed());
Thread.sleep(1000);
System.out.println(statement.isClosed());
}
产量
false
false
但是,如果您尝试调用set方法或execute,则会得到以下信息:
java.sql.SQLException: org.apache.commons.dbcp.DelegatingCallableStatement with address: "SQLServerCallableStatement:32" is closed.
at org.apache.commons.dbcp.DelegatingStatement.checkOpen(DelegatingStatement.java:137)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setInt(DelegatingPreparedStatement.java:120)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setInt(DelegatingPreparedStatement.java:120)
at com.ipti.ptl.common.messagetable.MessageHandlerTest.someTest(MessageHandlerTest.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) .....