This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes JDBC and the fly likes Lose connection to MySQL Database overnight Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Lose connection to MySQL Database overnight" Watch "Lose connection to MySQL Database overnight" New topic
Author

Lose connection to MySQL Database overnight

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 952
I have a Webapp that overnight loses its connection to the MySQL database.

I realize there is a timeout and I have code, in the servlet's POST, that does something like this:

if ( connection.isClosed())
{
this.initializeConnection();
}

The initializeConnection() method re-creates the connection from scratch.

Yet, still, first thing in the morning, when I start up the Web app, I'll see a "Communication link Failure" as a probable cause for the Web app failing. The code above seems to re-establish the link, but I still get errors.

On another version of MySQL (3.23) some users just get a blank screen. In 4.1, I seem to log in correctly.

What can I do to prevent this timeout or other issue?

Thanks very much for all replies!!!

- Mike
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Yup, I seem to recall the MySQL times out connections after 8 hours or something....

Unless you include a 'stay alive' message in the JDBC URL. I'll go look for it for you. You wait here
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Found it. Add ?autoReconnect=true to the end of your URL like this:


Thanks to atlassian.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 952
Thanks very much David!!!

I added this to the .properties file the servlet reads on init() or when it needs to re-create the connection.

I'll post another message tomorrow to let you know how this worked.

Thanks again!!!

-- Mike
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 952
To test, I tried to just restart MySQL. However, that doesn't appear to be where the timeout is held (I got no errors with or without the option you gave me). Perhaps Tomcat caches it somwhere?

I guess I'll have to wait 8 hours to test... <s>

-- Mike
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Lose connection to MySQL Database overnight
 
Similar Threads
MySQL Corruption Problem
java.net.SocketException: Broken pipe
database connection pooling confusion
How to connect to database without password using connection pooling
Can't find JDBC driver for project in MyEclipse