Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lose connection to MySQL Database overnight

 
Mike London
Ranch Hand
Posts: 1192
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found it. Add ?autoReconnect=true to the end of your URL like this:


Thanks to atlassian.
 
Mike London
Ranch Hand
Posts: 1192
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1192
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic