This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes db connection timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "db connection timeout" Watch "db connection timeout" New topic
Author

db connection timeout

Peter Straw
Ranch Hand

Joined: Jan 08, 2002
Posts: 79
I am having a problem with a connection object timing out in a servlet. The connection is created in a servlets init() method and is used indefinitely in synchonized methods throughout the servlet while the web application runs. This worked ok with microsoft sql, but now using mySql the connection times out and then creates SQLExceptions.
Does anyone know how best to fix this? Should I catch each sql exception and test for the connection being null and if it is create a new one? (Seems a bit long-winded). Or is there a Better Way?
Many thanks
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Use a connection pool. The simplest approach is to persuade your application server to make a DataSource available that you look up using JNDI. Otherwise, look into the Apache Jakarta Commons DBCP (DataBase Connection Pool).
- Peter
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: db connection timeout
 
Similar Threads
Connection Problem
maintaining a connection
jsp odbc problems
How can I fix this REALLY URGENT
Connect to db, simple question !!