• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Lose connection to MySQL Database overnight

 
Bartender
Posts: 1876
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found it. Add ?autoReconnect=true to the end of your URL like this:


Thanks to atlassian.
 
Mike London
Bartender
Posts: 1876
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1876
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic