关于com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
来源:互联网 发布:alias软件logo 编辑:程序博客网 时间:2024/05/16 23:50
最近早在处理一个小任务的时候遇到了这样的问题,相信有部分人也遇到过这样的问题。问题提示错误如下:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: java.net.BindException: Address already in use: connect
STACKTRACE:
java.net.SocketException: java.net.BindException: Address already in use: connect
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2565)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.tuan.util.toolsEasy.Tuan57.getConnection(Tuan57.java:34)
at com.tuan.util.toolsEasy.Tuan57.insertUrl(Tuan57.java:45)
at com.tuan.util.toolsEasy.Tuan57.brand(Tuan57.java:120)
at com.tuan.util.toolsEasy.Tuan57.main(Tuan57.java:161)
** END NESTED EXCEPTION **
当然还有部分,没有粘过来。看问题是是说链接数据库的次数过多导致的错误,怎么解决呢?这是重点(我用的是mysql)首先在mysql的数据库中分别输入下面三句话,并依此回车
set wait_timeout=604800;
set interactive_timeout=604800;
set global connect_timeout=604800;
然后在程序中判断一下,数据是否链接成功。我的代码如下
public class Tuan57 {
//String name,namePinyin,logo;
public static Connection connection;
static{
connection=getConnection();
}
public static Connection getConnection()
{
String driver ="com.mysql.jdbc.Driver";
String url = "-------------------------------------------------";
String userName = "root";
String password = "jiaobuhui";
try
{
if(connection!=null)return connection;
else {
Class.forName(driver);
return DriverManager.getConnection(url,userName,password);
}
}catch (Exception exc){
exc.printStackTrace();
return null;
}
}
这样就可以了。
- 关于com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:的解决
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:的解决
- 如何解决com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception
- 遭遇com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying
- Cause: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying...的解决
- Error: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying except
- Communications link failure due to underlying exception
- Communications link failure due to underlying exception
- Communications link failure due to underlying exception:
- Mysql报错!Communications link failure due to underlying exception
- iOS_判断异常出现在多少行
- win7 打开plsql登录不上显示空白提示框解决办法
- cocos2d-x 3.0sprite轮换
- 分享selenium+testng+reprotng+ant配置
- windows使用双网卡同时上内外网
- 关于com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- response.setContentType()的作用及参数
- 多线程详解
- gsoap传递数组方法
- 致公党江苏省委副主委应邀出席“引凤工程”网站建设讨论会
- Ogre学习(一)绘制一个立方体ManualObject(原)
- 常用DOS命令大全
- Fusioncharts工具从入门到提高
- FTP上传下载(Apache Commons Net)