commons-user mailing list archives

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

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
authentication.

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-sources>
		<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="***" />
		</data-source>
</data-sources>

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.
Sanjeet

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message