gpt4 book ai didi

mysql - 尝试从 spring mvc 应用程序在 mysql 中插入数据时获取 java.io.EOFException

转载 作者:行者123 更新时间:2023-11-29 00:53:02 27 4
gpt4 key购买 nike

我正在尝试将数据从 spring mvc app 提交到 mysql 。有时我会收到以下错误

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 **

只有几次我得到这个异常。

以下是我的配置文件:

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

我正在使用这些属性:

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

我正在使用:mysql-connector-java-5.0.5.jarMySQL 服务器 5 .

有时数据库连接正常,我得到了结果。

但有时它会产生错误。可能是什么问题?如果有任何想法请告诉..谢谢

最佳答案

事实上,MySQL 会在给定时间后断开打开的套接字。建议使用连接池(如c3p0)。

请参阅 MySQL 论坛上的这篇帖子 - http://forums.mysql.com/read.php?39,143312,180718#msg-180718 .这应该可以为您解决。

关于mysql - 尝试从 spring mvc 应用程序在 mysql 中插入数据时获取 java.io.EOFException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7470489/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com