Forums Register Login

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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
This is my favorite tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1465 times.
Similar Threads
How to use JNDI to get a Pooled Connection
Memory leaks
Problem with EJB 3. Name not bound error
BMP, Jboss, and mysql configuring
Not able to config the database!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:31:47.