The Java documentation of the interface java.sql.Connection says this about the close() method: "It is strongly recommended that an application explicitly commits or rolls back an active transaction prior to calling the close method. If the close method is called and there is an active transaction, the results are implementation-defined."
This creates a subtle but serious problem: If I call the rollback() method of a Connection but this method fails (for example, a timeout occurs), then can I call the close() method of this Connection? Is it possible that there is still an active transaction when I call the close() method, and so the results are implementation-defined, and so the transaction may be committed?
I can choose to not call the close() method if the rollback() fails, but this may make the JDBC resources not released. Furthermore, maybe eventually the close() method will be called (maybe when the Connection object is garbage-collected). If this is the case, then this approach will not help.
So, what should I do when the rollback() method of a Connection fails? If the rollback() method fails, can I still call the close() method of this Connection?