New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unexpected results for statement with closeOnCompletion #684
Comments
The |
I've recreated this same exception under different conditions using version 42.0.0. I have a generic Exception
Example code protected PreparedStatement getPreparedStatement(final String sql) throws ConnectException {
Connection connection = getConnection();
PreparedStatement statement = null;
try {
statement = connection.prepareStatement(sql);
statement.closeOnCompletion();
return statement;
} catch (SQLException ex) {
this.closeStatement(statement);
throw new ConnectException("Unable to get PreparedStatement.", ex);
}
}
protected void closeStatement(final Statement statement) {
try {
if (statement != null && !statement.isClosed() && !statement.isCloseOnCompletion()) {
// this close will cause the null pointer if I don't check isCloseOnCompletion first
statement.close();
}
} catch (SQLException ex) {
LOGGER.warning(String.format("Error closing statement: %s", ex.getMessage()));
}
} |
fixed by #1610 |
If a statement with
closeOnCompletion()
is executed a second time before its results have been consumed, it throws aNullPointerException
. I am unsure what the appropriate error is, but it should be more descriptive. Something like,org.postgresql.util.PSQLException: Statement with closeOnCompletion can not be executed twice.
.The following, where I close the result set, throws
org.postgresql.util.PSQLException: This statement has been closed.
, as I would expect.The text was updated successfully, but these errors were encountered: