commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sanjeet Joshi <>
Subject MySQL connection problem using DBCP
Date Mon, 11 Apr 2005 12:46:13 GMT

I am facing a problem with Connections to the database. 

Here is the development environment in short:

Struts, Jsp, Servlets and MySQL 4.1
I am using DBCP connection pooling.  The datasource configuration is
in struts-config.xml file. I am using container managed security for

I get EOFException when I try to login (or access the db for any other
purpose). This happens only after a long period of db inactivity.
Otherwise everything works fine.

When I searched for a solution, I found out that MySQL closes all
inactive connections after 8 hours. I also found out that setting a
MySQL attribute autoReconnect=true solves this. I tried setting it
along with my datasource config in struts-config.xml as follows:

		<data-source key="xyz" type="org.apache.commons.dbcp.BasicDataSource">
			<set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
			<set-property property="url" value="jdbc:mysql://localhost:3306/xyz" />
			<set-property property="autoReconnect" value="true" />
			<set-property property="username" value="***" />
			<set-property property="password" value="***" />

Is this the correct way of setting autoReconnect to true? Some
solutions suggested setting it along with the url i.e. like

<set-property property="url"
value="jdbc:mysql://localhost:3306/xyz?autoReconnect=true" />

Which of these is correct?

To test this solution I tried to reduce the wait_timeout and
interactive_timeout (both MySQL variables) from 8 hours to one minute.
The connections were closed after a minutes inactivity. But my webapp
worked absolutely fine (without autoReconnect="true") So I could not
get EOFException on my development machine.

Is there anyone who has faced this problem and solved it? Any Pointers
to any reading material about this?

Any help is appreciated.

Thanks in advance.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message