Exceptions and database connection

Asked

Viewed 39 times

1

I have a code that query a database. If a timeout exception occurs for example during the execution of the query, the connection closure code and consequent return of the connection to the pool will not occur, I must use a Try-Finally to even with exception pass through the connection closure code?

  • 1

    It is considered good practice for you to close connections with bank in block finally precisely so that, in case of success or error, it always be closed.

1 answer

1


should use a Try-Finally for even with exception pass through connection lock code?

Yes.

If you are using Java 7 or higher you can use Try-with-Resources.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.