java无法连接远程服务器数据库,jar远程连接数据库失败

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

我把项目导出为jar后,在我的电脑上能正常运行并且能访问数据库,但是在别人电脑上就会报错,报错如下:

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)

at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)

at b.conSQL.conMYSQL(conSQL.java:17)

at b.conSQL.checkIfUpdate(conSQL.java:28)

at a.hzx_METT$3.actionPerformed(hzx_METT.java:101)

at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)

at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)

at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)

at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)

at java.desktop/javax.swing.AbstractButton.doClick(AbstractButton.java:369)

at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1012)

at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1056)

at java.desktop/java.awt.Component.processMouseEvent(Component.java:6614)

at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)

at java.desktop/java.awt.Component.processEvent(Component.java:6379)

at java.desktop/java.awt.Container.processEvent(Container.java:2263)

at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4990)

at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)

at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)

at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)

at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548)

at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)

at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)

at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2769)

at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)

at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)

at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)

at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)

at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)

at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)

at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)

at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)

at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)

at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)

at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)

at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)

at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)

at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)

at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)

at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)

at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)

at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)

at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)

at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)

at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)

at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:89)

at com.mysql.cj.NativeSession.connect(NativeSession.java:144)

at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)

... 45 more

jdk版本:15.0.1

jdbc版本:8.0.22

mysql版本:8.0.22

大佬们帮帮忙

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值