• 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

Is the connection to the data base cossed properly.

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is one of the function to update in DAO. Can you please go through the code and let me know whether the database connection is closed properly or not. And also let me know if there is any changes required in code.




Thanks for your valuable time.
 
Ranch Hand
Posts: 129
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jaidev Arer wrote:Below is one of the function to update in DAO. Can you please go through the code and let me know whether the database connection is closed properly or not. And also let me know if there is any changes required in code.




Thanks for your valuable time.


The code snippet you have given is incomplete ...
you are calling getconnection() to get the connection ... is it a static method ?
you should have used if (con != null) con.close(); instead of con.close() and for for closing you prepared statement object also...
and why you are returning null ??? ...
 
Jaidev Arer
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vijin,

getconnection() is a static method.

Change the return type to void and removed the return null statement.

Is there method or function to call to close all the opened database connection explicitly?

Thanks again
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Is there method or function to call to close all the opened database connection explicitly?


No. But then if you are opening a connection you are presumably closing it once you are finished with it?

 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Closing p.close() in two places is unnecessary... Its enough to be retained in "finally" block itself since that block will be executed allegedly before getting out of the method. so guaranteed, connections are closed even an exception occurs or this update transaction is success...

Instead of returning String, return a "success" return code... you can use integers to indicate the result...
 
reply
    Bookmark Topic Watch Topic
  • New Topic