If I open up a JDBC connection in my java code and forget to close it, will it remain open for ever? Or is there a default time out value that I can specify somewhere?
Asked
Active
Viewed 2,021 times
2 Answers
4
In first place, you really need to fix the code to close it. No excuses.
As to the concrete question, that depends on the DB server used. It's the DB server who will timeout and reclaim it. Refer the DB server specific administration manual for defaults and how to change it. In case of for example MySQL, it's the wait_timeout
setting which defaults to 28800 seconds (8 hours).

BalusC
- 1,082,665
- 372
- 3,610
- 3,555
0
It depends on the specifics of the JDBC driver implementation. Some might have a timeout. Some might close when the connection object is garbage collected and finalize is called, but (1) you don't know how long after you stopped referencing the object it gets garbage collected, and (2) the finalize is not reliably called.

Marlin Pierce
- 9,931
- 4
- 30
- 52