- 浏览: 578571 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (411)
- webservice (3)
- oracle (37)
- sqlserver (8)
- j2ee (56)
- linux (7)
- javaweb (47)
- office (1)
- struts (23)
- hibernate (11)
- spring (29)
- 网络 (2)
- tomcat (13)
- tongweb (0)
- weblogic (0)
- powerdesiginer (3)
- svn (3)
- js (20)
- ie (2)
- 编译 (3)
- css (2)
- 操作系统 (5)
- Android (41)
- jbpm4.3 (1)
- fckeditor (3)
- 操作excel (2)
- db2常用命令 (1)
- ibatis (5)
- mysql (16)
- 表达式语言 (1)
- java方式调用存储过程 (1)
- ca (1)
- linux客户端 (1)
- 电子数码 (1)
- 行业应用 (12)
- 开发工具 (4)
- 面试 (1)
- 计算机原理 (1)
- NOSQL (5)
- 虚拟机 (1)
- nginx (0)
- velocity (2)
- jndi (1)
- spring mvc (39)
- springmvc (32)
- 安全 (5)
- htmleditor (6)
- iphone4 (1)
- html (4)
- jstl (2)
- ckeditor (5)
- 连接池 (1)
- jquery (6)
- 分页 (1)
- 技术研发规则 (1)
- javamail (1)
- maven (2)
- upload (1)
- log (1)
- 测试 (10)
- spring roo (1)
- 版本控制 (2)
- find bugs (0)
- jsf (0)
- springroo (0)
- 小道理 (1)
- 小道理,技术标准 (1)
- jsf (0)
- bitbao (2)
- redmine (3)
- 团队意识 (1)
- mybatis (2)
- jquery mobile (1)
- flexpaper (0)
- json (4)
- URLRewriteFilte (1)
- html5 (1)
- 都乐保活动 (0)
- openfire (0)
- TreeMap (1)
- build (0)
- javaweb,tag (0)
- algorithm (1)
- tag (2)
- 扯淡 (0)
- mac (2)
- 叶一火(老一) (1)
- 游玩 (1)
- 编码 (1)
- 上线部署 (0)
- 研发管理 (0)
- thumbnailator (2)
- 旅游 (0)
- bingweibo (1)
- 杂谈 (4)
- ktv (1)
- weibo (1)
- 爱情 (2)
- 饮食 (1)
- MediaWiki (1)
- git (1)
- 版本库 (1)
- servlet (1)
- 感悟 (1)
- 人生 (1)
- highcharts (1)
- poi (0)
- websphere (0)
- php (1)
最新评论
-
woshixushigang:
good
org.springframework.beans.TypeMismatchException: Failed to convert property valu -
nathanleewei:
org.springframework.jdbc.core.B ...
org.springframework.beans.TypeMismatchException: Failed to convert property valu -
浪禾木:
请问是ckeditor\contents.css吗?改过以后 ...
ckeditor自动换行问题 -
simusuishi:
刚哥威武!
ckeditor取值赋值问题 -
a455642158:
收割完毕……
Android开源项目源码下载(不断更新中)
Connector/J connection property 'autoReconnect=true' to avoid this problem.
最近做的比特宝项目发现每次进入测试服务器时候都报这个错误:Connector/J connection property 'autoReconnect=true' to avoid this problem.
错误日志如下:
Connector/J connection property 'autoReconnect=true' to avoid this problem. at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:603) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:662) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:702) at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:178) at com.bitbao.cm.dao.UDBUserDao.getUserByUidForAccount(UDBUserDao.java:334) at com.bitbao.cm.controller.WebBaseController.listLeftBar(WebBaseController.java:59) at com.bitbao.cm.controller.WebBaseController.preHanle(WebBaseController.java:44) at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:162) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:863) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:851) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:756) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:438) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302) at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:421) at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:342) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:554) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:662) Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 153,619,009 milliseconds ago. The last packet sent successfully to the server was 153,619,010 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3352) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1971) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2281) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:644) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:587) ... 36 more Caused by: java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) at java.net.SocketOutputStream.write(SocketOutputStream.java:136) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3333) ... 44 more
引入几个解决方案:
第一种:
属性文件 c3p0.driverClass=com.mysql.jdbc.Driver c3p0.user=root c3p0.password=edwin c3p0.jdbcUrl=jdbc\:mysql\://192.168.1.123\:3306/edwin?useUnicode\=true&characterEncoding\=utf-8 c3p0.minPoolSize = 1 c3p0.maxPoolSize = 50 c3p0.initialPoolSize = 1 c3p0.maxIdleTime = 25000 c3p0.acquireIncrement = 1 c3p0.acquireRetryAttempts = 30 c3p0.acquireRetryDelay = 1000 c3p0.testConnectionOnCheckin = true c3p0.automaticTestTable = t_c3p0 c3p0.idleConnectionTestPeriod = 18000 c3p0.checkoutTimeout=5000 --------------------------------------------------------- spring配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName" default-lazy-init="false"> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>classpath:com/edwin/db/config/c3p0.properties</value> </property> </bean> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>${c3p0.driverClass}</value> </property> <property name="jdbcUrl"> <value>${c3p0.jdbcUrl}</value> </property> <property name="user"> <value>${c3p0.user}</value> </property> <property name="password"> <value>${c3p0.password}</value> </property> <property name="minPoolSize"> <value>${c3p0.minPoolSize}</value> </property> <property name="maxPoolSize"> <value>${c3p0.maxPoolSize}</value> </property> <property name="initialPoolSize"> <value>${c3p0.initialPoolSize}</value> </property> <property name="maxIdleTime"> <value>${c3p0.maxIdleTime}</value> </property> <property name="acquireIncrement"> <value>${c3p0.acquireIncrement}</value> </property> <property name="acquireRetryAttempts"> <value>${c3p0.acquireRetryAttempts}</value> </property> <property name="acquireRetryDelay"> <value>${c3p0.acquireRetryDelay}</value> </property> <property name="testConnectionOnCheckin"> <value>${c3p0.testConnectionOnCheckin}</value> </property> <property name="automaticTestTable"> <value>${c3p0.automaticTestTable}</value> </property> <property name="idleConnectionTestPeriod"> <value>${c3p0.idleConnectionTestPeriod}</value> </property> <property name="checkoutTimeout"> <value>${c3p0.checkoutTimeout}</value> </property> </bean> </beans>
二种. 如果不用hibernate的话, 则在 connection url中加参数: autoReconnect=true
jdbc.url=jdbc:mysql://ipaddress:3306/database?autoReconnect=true&autoReconnectForPools=true
三种。用hibernate的话, 加如下属性:
<property
name="connection.autoReconnect">true</property>
<property
name="connection.autoReconnectForPools">true</property>
<property
name="connection.is-connection-validation-required">true</property>
四。要是还用c3p0连接池:
<property
name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">0</property>
<property
name="hibernate.c3p0.timeout">0</property>
<property
name="hibernate.
c3p0.validate">true</property>
最不好的解决方案
使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误:
Communications link failure,The last packet successfully received from the server was *** millisecond ago.The last packet successfully sent to the server was *** millisecond ago。
其中错误还会提示你修改wait_timeout或是使用Connector/J的autoReconnect属性避免该错误。
后来查了一些资料,才发现遇到这个问题的人还真不少,大部分都是使用连接池方式时才会出现这个问题,短连接应该很难出现这个问题。这个问题的原因:
MySQL服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。
1.按照错误的提示,可以在JDBC URL中使用autoReconnect属性,实际测试时使用了autoReconnect=true& failOverReadOnly=false,不过并未起作用,使用的是5.1版本,可能真像网上所说的只对4之前的版本有效。
2.没办法,只能修改MySQL的参数了,wait_timeout最大为31536000即1年,在my.cnf中加入:
[mysqld]
wait_timeout=31536000
interactive_timeout=31536000
重启生效,需要同时修改这两个参数。
发表评论
-
RESTFUL
2013-05-29 17:21 0a -
hibernate命名查询问题
2013-01-30 16:38 1323hibernate 注解 @OneToOne(fetc ... -
hibernate [Null value was assigned to a property of primitive type setter of sco
2012-12-25 19:51 1115今天开发时候 hibernate 查询报错,分析原因如下: ... -
Servlet线程安全问题
2012-10-07 11:52 1020进来休息下,来点我吧 摘 要:介绍了Servlet多线程 ... -
from_unixtime,unix_timestamp
2012-10-07 09:30 1256进来休息下,来点我吧 from_unixtime() ... -
Collections.addAll
2012-09-07 18:04 2330collections用法以及list 简单实例 Colle ... -
string
2012-09-06 17:20 892String a = "ab"; ... -
mysql utf-8编码 一个汉字占用3个字节
2012-09-05 16:18 1053最近在弄新鲜事分享,转发以及评论,发现输入发自带的表情占用四个 ... -
mapper.readValue读取null
2012-08-17 19:21 2606如下代码,这样写不会走catch方法,此方法不报ioExcep ... -
string.split(",")返回的长度问题
2012-08-17 15:38 918String test = "#我的测试#&q ... -
thumbnailator 图片缩放问题
2012-08-17 19:29 2753这段代码上传1.7m图片会报错: publ ... -
模拟微博新鲜事短网址处理方式
2012-08-16 17:40 0a -
新鲜事短连接
2012-08-19 12:01 958现在需求如下: 使 ... -
jackson objectMapper.readValue 读取并存成想要的类型
2012-07-26 20:16 3716两种方式: java反射里面有个很有趣的东东,反射解析成li ... -
spring mvc responseBody 会把特殊字符转义
2012-07-26 19:53 4509框架用的spring 采用spring mvc 方式进行图片上 ... -
Out of range value for column 'bindUid' at row 1
2012-07-19 20:35 1495今天弄新浪微博绑定,数据库oauth_token表需要插入bi ... -
图片复制
2012-07-05 11:53 1068import java.io.File;import java ... -
thumbnailator 图片缩放
2012-07-04 20:10 1386Thumbnailator是一个用来生成图像缩略图的 J ... -
spring mvc 自己遇到的几个错误
2012-06-13 14:36 1202where 1=1 and t.name like '%&q ... -
Request method 'POST' not supported
2012-06-08 10:53 5209项目采用spring mvc框架实现,插入数据时候采用 ...
相关推荐
autoReconnect=true</property> <property name="user">root</property> <property name="password">password</property> <property name="initialPoolSize">10</property> <property name="minPoolSize">10</...
autoReconnect=true"/> <param name="schemaObjectPrefix" value="rep_"/> <param name="schema" value="mysql"/> <param name="user" value="openkm"/> <param name="password" value="123456"/> </FileSystem...
autoReconnect=true&useUnicode=true&characterEncoding=UTF8</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> ...
useUnicode=true&characterEncoding=UTF-8&autoReconnect=true jdbc.username=root jdbc.password=kfs cpool.checkoutTimeout=5000 cpool.minPoolSize=10 cpool.maxPoolSize=25 cpool.maxIdleTime=7200 cpool....
<property name="connection.datasource">dataSource</property> <!-- 其他 Hibernate 配置信息 --> </session-factory> </hibernate-configuration> ``` 在上面的配置中,我们使用 DynamicDataSource 作为 ...
<property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.ProxoolConnectionProvider</property> <property name="hibernate.proxool.pool_name">my_pool_name</...
autoReconnect=true ``` 6. **connectTimeout**: 设置连接超时时间(毫秒)。 ```text jdbc:mysql://localhost:3306/mydb?connectTimeout=10000 ``` 7. **useAffectedRows**: 是否返回实际受影响的行数,而...
useUnicode=true&characterEncoding=GB2312&autoReconnect=true jdbc.username.mysql=root jdbc.password.mysql=root 3、 Web容器:tomcat6.x 4、 页面访问路径: 论坛首页: http://localhost:8080/bbs 后台管理...
一.开发环境 IDEA + JDK8 + MySQL5.7 + navicate 二.技术栈 Springboot+Mybatis+layui 三....数据库地址url修改为 spring.datasource.url=jdbc:mysql://localhost:3306/score?...autoReconnect=true&use
autoReconnect=true"/> <property name="username" value="root"/> <property name="password" value="123456"/> <property name="initialSize" value="100"/> <property name="maxIdle" value="10"/> ...
autoReconnect=true</prop> <prop key="hibernate.connection.username">root</prop> <prop key="hibernate.connection.password">1234</prop> </props> </property> </bean> ``` ##### 3. DAO层设计 为了实现...
autoReconnect=true" // 数据库URL maxActive="4"/> // 最大活动连接数 ``` 这种方式的效果与在Tomcat管理界面中设置相同。 2. 或者在$Tomcat/conf/server.xml的`<Context>`标签内添加以下代码: ```xml ...
《Nacos插件与MySQL Connector/J 8.0.19的深度理解与应用》 在现代企业级的分布式系统中,Nacos作为一款优秀的动态服务发现、配置管理和服务管理平台,扮演着至关重要的角色。而MySQL作为广泛使用的开源关系型...
<Resource name="zk" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="(此处填你的数据库用户名)" password="(此处填你的数据库密码)" driverClassName=...
characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true db.url.1=jdbc:mysql://11.163.152.9:3306/nacos_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&...
useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true jdbc.username=root jdbc.password=123456 ``` - **`log4j.properties`**: ```properties log4j.rootLogger=DEBUG,A1 ...
6. **配置参数**:MySQL Connector/J支持多种配置参数,如`useUnicode=true`、`characterEncoding=utf8`用于设置字符编码,`autoReconnect=true`用于确保断线后自动重连等。 7. **兼容性与版本**:5.1.5版本的MySQL...
MySQL Connector/J 3.0.12 是 MySQL 官方提供的用于 Java 应用程序连接 MySQL 数据库的驱动程序。这个压缩包包含了该版本的驱动程序及相关文件,为开发者提供了在 Java 平台上与 MySQL 数据库进行交互的能力。以下是...