This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes JDBC connection problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC connection problem" Watch "JDBC connection problem" New topic
Author

JDBC connection problem

Arvind Purohit
Ranch Hand

Joined: Jun 18, 2010
Posts: 43
Arvind Purohit wrote:Hi All
I am trying to connect a data base. below i have given the code. I am able to connect to data base but unable to connect 2nd time if difference between 1st time and 2nd time is greater then "wait time out" of mysql data base.
I am using mysql data base. I am getting "Communications link failure" problem
wait_timeout is 10 sec (for convenience) it is 8 hour for my DB
I am giving you code


AND I am testing like


and it is giving exception like


Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
I don't know if this is your problem but you are not closing your connection, statement or result set. I see you are also eating the DatabaseInitializationException in getInstance().
Arvind Purohit
Ranch Hand

Joined: Jun 18, 2010
Posts: 43
Tom Reilly wrote:I don't know if this is your problem but you are not closing your connection, statement or result set. I see you are also eating the DatabaseInitializationException in getInstance().

Thanks for your reply...
I am not getting what do you want to say. how do i solve this problem

Thanks
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
You need to tell JDBC that you are done using its resources. Examples:

Statement.close()
ResultSet.close()
Connection.close()

Take a look at one of the JDBC tutorials out there. I haven't looked at one in years so cannot recommend a good one. Perhaps someone else can.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: JDBC connection problem
 
It's not a secret anymore!