So far I have never seen a PreparedStatement throws an SQLException on close, but I would like to know when it would throw the exception and what is the best practice to deal with it.
Thank you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’d log this as a WARNING. If this happens more than once in a while, I’d want to investigate what is going on here.
If this is part of a transaction, I would abort and rollback the transaction (which probably also fails, but I wouldn’t want to continue using this connection). So I guess, this means: rethrow, as an SQLException if the method already has this exception, otherwise as a RuntimeException (because this really should not happen at all, and I would not want to mess up my declared exceptions because of it).
If this is after a commit in the final clean-up step, I’d just ignore it and continue to try to close the rest of the connection.