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.
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.