• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Database connection wont work 1st time but will work 2nd time? Help.

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all. I'm new to the forum and excited to be here.

I have a project written in struts with jsp pages and servlets. I access a mysql database that is on the same server as the code which is running on Tomcat 5.0. I am using a datasource for the mysql database in the code. I have this strange issue. If no one logs into the website for a awhile, when you try to login, the site just hangs and it doesn't make the connection to the database. However if you then press the login button again, which will re-create the datasource connection, it works perfectly and connects, logs in, etc... Then any attempts to login to my application will work fine for a certain period of time (seems to be at leaast 30 minutes, might be quite a lot longer), even in a brand new browser session.

So it seems like after a certain period of time the datasource dies in some way, but then once I "wake it up", after the first failure, it will work again.

Anyone have any ideas?

I can't access my server log till Tuesday to see if there are any hints, but I wanted to get this question out there to see if it sounds familiar. Thanks for any help
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect you're using pooled connections.

By default, a MySQL DB terminate a connection after it's been idle long enough. I'd guess that you're not testing connections when the pool hands them out (most poolers can be configured to do this for you, and not dealing with the broken connection appropriately (or perhaps mysql is not responding to activity on that connection and your DB request hangs).

While you might be able to get MySQL to change the way it behaves, you really need to code for intermittent errors anyway. Stuff happens. Once in a while databases get restarted, etc. etc.
 
Claude Forkner
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was thinking of something like that.

So do you recommend when I first create the connection in my code (when the user clicks the login button) that I check the connection and if it is closed I just try to create a connection again - which ususally would work the second time?

Thanks.
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic