swaldman / c3p0

a mature, highly concurrent JDBC Connection pooling library, with support for caching and reuse of PreparedStatements.
http://www.mchange.com/projects/c3p0
Other
1.29k stars 339 forks source link

java.lang.InternalError: Marking a ResultSet inactive that we did not know was opened! #104

Open crowmagnumb opened 6 years ago

crowmagnumb commented 6 years ago

Using a c3p0 (v0.9.5.2) connection from a ComboPooledDataSource to perform a simple SQL SELECT statement using postgres I get the following error if I use statement.executeQuery() ...

java.lang.InternalError: Marking a ResultSet inactive that we did not know was opened!

... but if I use statement.execute() it's fine. What is going on there? Here is my code where connectionProvider is a ComboPooledDataSource ....

Connection connection = connectionProvider.getConnection();
Statement statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = statement.executeQuery();

After stepping through the ResultSet I perform a statement.close() and get ...

java.lang.InternalError: Marking a ResultSet inactive that we did not know was opened!
    at com.mchange.v2.c3p0.impl.NewPooledConnection.markInactiveResultSetForStatement(NewPooledConnection.java:353)
    at com.mchange.v2.c3p0.impl.NewProxyResultSet.close(NewProxyResultSet.java:844)
    at com.mchange.v2.c3p0.impl.NewProxyStatement.close(NewProxyStatement.java:162)

If, however, sub statement.execute() for statement.executeQuery() I don't have this problem.

4shotespresso commented 6 years ago

Any resolution to this, besides switching to statement.execute()?

4shotespresso commented 6 years ago

If it helps, my bug was a matter of accessing a ResultSet on the PreparedStatement vs on the DBConnection object. Not a C3P0 issue.

BAD 2245 | < | while(dbCon.getPrepStmt().getResultSet().next()){ 2246 | < | int count = dbCon.getPrepStmt().getResultSet().getInt("c");

GOOD 2245 | > | while(dbCon.getResultSet().next()){ 2246 | > | int count = dbCon.getResultSet().getInt("c");