Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes Closing DB issue in new method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Closing DB issue in new method" Watch "Closing DB issue in new method" New topic
Author

Closing DB issue in new method

Ed Carrington
Ranch Hand

Joined: Oct 11, 2007
Posts: 77
I have a method that inserts data into my Oracle 9i database with no problems and no Database closing issues:


Now when I put the method (inserter) in another class called OtherClass, it does insert the data but now I have database closing issues:



In my SQL Plus database resource check I see JDBC Thin Client is opened and not closed after each insert with the above attempt.
This didnt happen when I had the method in the same class.

Please advise.
[ October 15, 2007: Message edited by: Ed Carrington ]
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

Even though this probably sounds excessive, your finally code should be protected line by line as such:


I've seen people not do this in the past and keep in mind, if an rs.close() or stmt.close() fails then without this type of structure the conn.close() might not be executed.

If it helps I usually add these add as static utility functions so I don't have to write this over and over again.


My Blog: Down Home Country Coding with Scott Selikoff
Ed Carrington
Ranch Hand

Joined: Oct 11, 2007
Posts: 77
Originally posted by Scott Selikoff:
Even though this probably sounds excessive, your finally code should be protected line by line as such:


I've seen people not do this in the past and keep in mind, if an rs.close() or stmt.close() fails then without this type of structure the conn.close() might not be executed.

If it helps I usually add these add as static utility functions so I don't have to write this over and over again.



Thanks I added as you suggested and still have the database closing issue.
Please advise.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing DB issue in new method
 
Similar Threads
Hibernate Connection Pool
Synchronization Problem whil accessing JDBC Code
Pool connection leak error
Single Database connection
Data type mapping issue