File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Lose connection to MySQL Database overnight Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
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: 1034
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: 1034
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: 1034
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://aspose.com/file-tools
 
subject: Lose connection to MySQL Database overnight
 
Similar Threads
database connection pooling confusion
Can't find JDBC driver for project in MyEclipse
How to connect to database without password using connection pooling
java.net.SocketException: Broken pipe
MySQL Corruption Problem