• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Result of JDBC connection not closed

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic