Communication link failure: java.net.SocketException

这个主要是mysql长时间没连接就会自动断开的原因。

解决方法:

1、在连接参数中添加如下属性autoReconnect=true,具体如下:

<Resource name="test"   
        auth="Container"   
        type="javax.sql.DataSource"  
        driverClassName="com.mysql.jdbc.Driver"  
        url="jdbc:mysql://localhost:3306/test"  
        username="root"   
        password="test"  
        maxActive="100"   
        maxIdle="10"   
        maxWait="120000" 
	autoReconnect="true"  
 

2、用连接池(仅是思路,未测试)

3、将mysql服务设为自动重启:(思路,未测试)

开始菜单-运行-services.msc

找到mysql的服务并双击

点击恢复选项卡

第一次失败:默认是“不操作”,改成”重新启动服务”。

在下方的“重新启动服务:___分钟后”添上“0”表示如果服务意外终止则立即重启动。

点击确定使设置生效。

这时候你在任务管理器里结束mysql-nt进程,会发现结束不掉。

refurl:http://bbs.csdn.net/topics/300211091

http://www.webdeveloper.com/forum/showthread.php?97823-Error-Communications-link-failure-due-to-underlying-exception

http://blog.csdn.net/biexf/article/details/5954432

http://www.kitesky.com/20101202/1112.html

猜你喜欢

转载自wandejun1012.iteye.com/blog/1766826
今日推荐