Originally posted by Babji Reddy:
close() will not make the connection eligible for GC. It just releases JDBC resources that are used by that connection.
Right.
To be clear for the questioner: just like elsewhere in
Java, an object becomes eligible for GC when and only when there are no more references to it (we'll ignore weak references since they sort of don't count for GC purposes). In well-designed code, stale objects go out of local scope quickly and then become eligible for GC; in poorly designed code, objects can have global scope and hacks like setting things null get used to compensate for the poor design.
A common poor coding practice is to have a Connection member variable in the class because the programmer is too lazy to type a new local variable in each method that uses a connection briefly. Then for long-lived class objects, it becomes necessary to junk up the code with "conn = null" to force appropriate short-lived behaviour on the connection objects.