Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.sql.SQLException: Closed Statement when using PreparedStatement

264077Apr 24 2002
Hello all,

I'm attempting to execute two prepared statements from the same connection and everytime I do I get this error:

java.sql.SQLException: Closed Statement
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:273)
at oracle.jdbc.driver.OracleStatement.ensureOpen(OracleStatement.java:47
68)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePrepar
edStatement.java:349)
at com.knowledgecc.coplink2.Admin.AdminProcedures.updateUsersPrefer(Admi
nProcedures.java:2261)

This is the code that is being used:
sql1 and sql2 are different sql statements

Connection con = null;
con = ConnectionPoolMgr.getConnection(connectionType);

PreparedStatement prestmtDel = con.prepareStatement(sql1, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
prestmtDel.setString(1, user.getUserName());
prestmtDel.setString(2, formName + ".%");
prestmtDel.executeUpdate();
prestmtDel.close();
PreparedStatement prestmtInsert = con.prepareStatement(sql2, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
prestmtInsert.setString(1, user.getUserName());
prestmtInsert.setString(2, formName + "." + name);
prestmtInsert.setString(3, value);
prestmtInsert.executeUpdate();
prestmtInsert.close();

ConnectionPoolMgr.freeConnection(connectionType, con);

The first prepared statement will query, but the second throws the exception on the executeUpdate line. I'm using the brand new (downloaded today) Oracle 9i driver. The Connection is created as a regular connection - not an OracleConnection. Is this because of the Implicit Caching? Is the driver giving me logical connections instead of physical ones? This code DOES work with other drivers of other databases....

I've searched through the forums but never really found any answers that address this problem directly (though there are some people who seem to have the same problem I do). Any and all help is greatly appreciated....

Thanks in advance
--Andy
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 28 2002
Added on Apr 24 2002
1 comment
2,451 views