开发者

getting java.io.EOFException when trying to insert data in mysql from spring mvc app

I am trying to submit data from spring mvc app to mysql . sometime i get the following error

org.springframework.dao.DataAccessResourceFailureException: StatementCallback; SQL [insert into networkwithusdb(company,firstname,lastname,email,address1,address2,city,state,zipcode,currentemployer,currentjobtitle,primarycareerarea,secondarycareerarea) values('HCA North Texas','dd','af','bhanukiran@imomentous.info','','','','KS','','','','Facilities','Facilities')]; Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.io.EOFException

STACKTRACE:

java.io.EOFException
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1963)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2375)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2874)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3243)
    at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1343)
    at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1260)
    at org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)
    at org.springframework.jdbc.core.JdbcTemplate$1UpdateStatementCallback.doInStatement(JdbcTemplate.java:508)
    at org.springframework.jdbc.core.JdbcTemplate$1UpdateStatementCallback.doInStatement(JdbcTemplate.java:1)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:395)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:518)
    at com.imomentous.hcanorthtexas.service.DatabaseService.insertNetworkData(DatabaseService.java:58)
    at com.imomentous.hcanorthtexas.controller.NetworkWithUsController.processNetworkWithUSForm(NetworkWithUsController.java:62)
    [... snip ...]    

** END NESTED EXCEPTION **

only few times i get this exception.

following are my configuration file:

<bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName">
        <value>${database.driver}</value>
    </property>
    <property name="url">
        <value>${database.url}</value>
    </property>
    <property name="username">
       开发者_运维技巧 <value>${database.username}</value>
    </property>
    <property name="password">
        <value>${database.password}</value>
    </property>
    <property name="maxActive" value="5" />
    <property name="initialSize" value="3" />
    <property name="validationQuery" value="SELECT 5 FROM DUAL" />
    <property name="testOnBorrow" value="true" />

</bean>

and i am using the properties as:

database.driver =com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost:3306/XXXmobiledb
database.username=XXXX
database.password=XXXX

i am using:mysql-connector-java-5.0.5.jar mysql server 5 .

sometimes database connection works properly and i get the result.

but sometimes it generates the error. what might be the problem? If any have some idea please tell..thanks


The fact is that MySQL will disconnect the opened socket after a given time. You are advised to use a connection pool (such as c3p0).

See this post on the MySQL forum - http://forums.mysql.com/read.php?39,143312,180718#msg-180718. This should resolve it for you.


It might happen after a long time of inactivity add validation Query to your dataSource bean:

<property name="validationQuery">
<value>Select 1</value>
</property>


To avoid MySQL from disconnecting your session after a given idle time, you can use Spring OpenSessionInViewFilter or Interceptor to handle session.

This will require additional session filter settings in your web.xml file. You can mimic this post.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜