wood burning stoves 2.0*
The moose likes JDBC and the fly likes Result of JDBC connection not closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Result of JDBC connection not closed " Watch "Result of JDBC connection not closed " New topic
Author

Result of JDBC connection not closed

RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
Hi !


I want to ask what if i do not close my Jdbc connection..??

Would it be removed by garbage collector..??

or what will be the result

Thanks in Advance

Raman S
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You need to be wary when the resources used are not Java resources. A database Connection is owned and managed by the database, the Class just gives you access to that database resource. If you don't close the connection then the Java class can be garbage collected, but the Database may not be able to tell that the connection is no longer in use, which may result in database resources being wasted or even leak.

Other places to be careful are File and IO operations, and also when using Graphics contexts as these are system resources.
RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
Hi David!
Thanks for your reply

so if connection is not closed it will remain open for a specified time or forever

and it will consume our heap space also... M i right..??

as i m new to java..
sorry if i asked foolish one..??


Thanks
Raman S
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

no, it will consume resources on the database.
RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
ok david,


so how long it will exists , i mean it will remain open for specified time..??

Thanks

Raman
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

There is no easy answer for that. For databases it will be up to each engine, for system resources I have no idea, but consider in both cases that if you are performing operations very quickly (eg double buffered graphics or a busy web site) it would probably be easy to use up all of the resources before they became available again.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

Yes, because the exact effect is not always given, you will have to assume:
- If I don't return a connection, I will occupy that resource for a very long time, a time not manageable or predictable by me.


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Result of JDBC connection not closed