数据库连接错误:Communications link failure due to underlying exception

过了年回来,调整好状态后,继续进行springcloud的学习!

今天的学习中又碰到了一个之前没碰到的问题,数据库连接错误:Communications link failure due to underlying exception,具体错误信息如下所示:

[org.jboss.resource.connectionmanager.JBossManagedConnectionPool] Throwable while attempting to get a new connection: null 
org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (com.mysql.jdbc.CommunicationsException: 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:1934) 
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2380) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2909) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:798) 
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3700) 
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1203) 
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2572) 
    at com.mysql.jdbc.Connection.<init>(Connection.java:1485) 
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266) 
    at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:172) 
    at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:619) 
    at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:264) 
    at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:575) 
    at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:347) 
    at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:330) 
    at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:402) 
    at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:849) 
    at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:89) 
    at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112) 
    at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166) 
    at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 
    at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 
    at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 
    at org.jboss.ejb3.tx.BMTInterceptor.handleStateless(BMTInterceptor.java:71) 
    at org.jboss.ejb3.tx.BMTInterceptor.invoke(BMTInterceptor.java:131) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 
    at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 
    at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 
    at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77) 
    at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 
    at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 
    at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106) 
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 
    at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304) 
    at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106) 
    at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82) 
    at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:809) 
    at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:608) 
    at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:420) 
    at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:173) 


** END NESTED EXCEPTION ** 


Last packet sent to the server was 22 ms ago.) 


看了半天报错信息,也没看出什么名堂来,于是求助百度,百度上给的答案大多都是提高mysql端的timeout值,或者降低连接池这边的timeout值,我也尝试着去改了,还有一些其他的解决方案,但在我这儿都行不通,我就纳闷了,咋回事,然后一想会不会是我的mysql服务停了?然后赶紧看看,果然,本地mysql服务没有启,那肯定是连接不上咯!

启动一下mysql服务,然后再次访问,一切正常!

顺便说一下启动mysql服务的方法吧:

方法1:

windows+R打开cmd命令行界面,输入 net start mysql,即可启动mysql服务,如下图


停止服务的命令是 net stop mysql,如图


方法二:

右键我的电脑->管理


然后服务和应用程序->服务


然后找到mysql服务


选中然后右键选择启动,或者停止即可。


好了,到此结束,我要去跑步了!

本文为原创,如需转载,请注明出处,谢谢!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`com.mysql.jdbc.CommunicationsException`是MySQL JDBC驱动程序中的一个异常,它表示在尝试连接到MySQL数据库时出现通信故障。这个异常通常是由于以下原因之一引起的: 1. 数据库服务器已关闭或未启动。 2. 数据库服务器上的端口号不正确。 3. 防火墙或其他网络设备阻止了连接。 4. 数据库服务器上的连接数已达到最大值。 要解决这个问题,可以尝试以下几个步骤: 1. 确保MySQL服务器正在运行,并且端口号正确。 2. 检查防火墙或其他网络设备是否阻止了连接。 3. 检查MySQL服务器的日志文件以获取更多信息。 4. 如果连接数已达到最大值,请增加MySQL服务器上的最大连接数。 以下是一个示例代码,可以用来连接MySQL数据库并捕获`com.mysql.jdbc.CommunicationsException`异常: ```java import java.sql.*; public class Example { public static void main(String[] args) { try { // 连接到MySQL数据库 String url = "jdbc:mysql://localhost:3306/mydatabase"; String user = "root"; String password = "mypassword"; Connection conn = DriverManager.getConnection(url, user, password); // 执行SQL查询 Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM mytable"); // 处理查询结果 while (rs.next()) { System.out.println(rs.getString("column1")); } // 关闭连接 rs.close(); stmt.close(); conn.close(); } catch (SQLException e) { // 捕获CommunicationsException异常 if (e instanceof CommunicationsException) { System.out.println("通信故障:" + e.getMessage()); } else { e.printStackTrace(); } } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值