Implement AutoCloseable in JDBC connection classes - #338
Conversation
Signed-off-by: Rafał Gała <rafal.gala@hotmail.com>
|
Are you sure this actually needed? java.sql.Connection already implements AutoCloseable, while PooledConnection doesn't implement AutoCloseable by design (closing is handled by the pool manager) |
|
PooledCnnection class supports close() method which does not really close the connection but returns it to the pool. With AutoCloseable support it would be possible to obtain pooled connections in try-with-resources blocks and return them to the pool automatically without a need of calling close() method explicitly. |
|
Sorry but I don't agree - even the PooledConnection's javadoc state that the close method shouldn't be called by the application. |
|
Then why was this method implemented in AS400JDBCPooledConnection class? Here is a sample code from IBM directly and as you can see, close method is called to return connection to the pool and AFAIK this is the only way to do it - https://www.ibm.com/docs/en/i/7.6.0?topic=classes-as400jdbcconnectionpool I am confused with Oracle's documentation, it says that applications never call close method directly, but then:
|
|
The IBM example uses Connection, not PooledConnection. PooledConnection are not meant to be used by final applications, that's the key point and the reason the class doesn't implement AutoCloseable. |

Added AutoCloseable implementation to JDBC connection classes so they can be used in try-with-resources blocks.