• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Result of JDBC connection not closed

 
RamandeepS Singh
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, it will consume resources on the database.
 
RamandeepS Singh
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok david,


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

Thanks

Raman
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic