Some JDBC connection implementations will close()
when they are garbage collected. An example of this is in the Postgres JDBC driver in its finalize() method (code here). There is no guarantee this is the case, though.
But...
There is no way to know when a garbage collection of the connection objects will take place. The garbage collector has no knowledge about JDBC resources, just about memory. This means that a GC may only occur when there is a need to free up memory. If you have 60 connections sitting around but there is still free memory the GC wont run and you'll end up running out of connections.
It is also possible that some kind of JDBC connection pooling is happening. This means that the Connection
object you get isn't the real connection but one that is wrapped up in pooling logic. If you don't close()
these connections, the pool wont know you are finished with them and wont be able to reuse them for other requests, and the connection pool will be exhausted.
So always close()
your connections explicitly if you create them.