简体   繁体   English

本地主机上的JDBC无法连接

[英]JDBC on localhost doesn't connect

I can't connect to the local database even if the connection parameters are correct, using jdbc. 即使连接参数正确,我也无法使用jdbc连接到本地数据库。 If I try to connect by terminal or by some client i can connect. 如果我尝试通过终端或某些客户端进行连接,则可以连接。

But if I try to connect to remote database it works 但是,如果我尝试连接到远程数据库,它将起作用

this is the error: 这是错误:

Connected to the target VM, address: '127.0.0.1:49986', transport: 'socket'
Exception in thread "main" 2019-04-15 12:16:55 FATAL AbstractConnectorDB - Unable to connect to database jdbc:mysql://localhost:3306/my_db?autoReconnect=true&useSSL=false
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
com.mycompany.database.relational.exceptions.ConnectionFailedException:     Fatal error: Unable to connect to db jdbc:mysql://localhost:3306/my_db?autoReconnect=true&useSSL=false @root
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    ...
    ... 17 more
Disconnected from the target VM, address: '127.0.0.1:49986', transport: 'socket'



What could be the problem? 可能是什么问题呢?

Yes, your connection properties are correct on your PC but not on the VM. 是的,您的连接属性在PC上正确,但在VM上正确。 Use your PC's IP Address instead. 请改用PC的IP地址。

The source of the problem was: I was using MySQL version 5 in my POM, but I had MySQL 8 on my computer. 问题的根源是:我在POM中使用的是MySQL 5,但是我的计算机上有MySQL 8。
So I completely deleted MySQL from my computer and installed the version I needed 因此,我从计算机上完全删除了MySQL,并安装了所需的版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM