我正在使用hibernate将Java程序连接到mysql数据库,但出现错误

我正在使用hibernate将Java程序连接到mysql数据库,但出现错误,java,mysql,database,hibernate,Java,Mysql,Database,Hibernate,堆栈跟踪: Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Could not open connection at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:67) at org.hibernate.exception.inte

堆栈跟踪:

Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Could not open connection
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:67)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
    at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1396)
    at com.telusko.DemoHibb.App.main(App.java:24)
我的Hibernate.cfg.xml文件是:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/neon</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hbm2ddl.auto">update</property>
    </session-factory>
</hibernate-configuration>

com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/neon
根
根
org.hibernate.dialogue.mysqldialogue
使现代化

请检查您的MySQL服务器是否正在运行:

适用于Unix(sh):

适用于Windows(cmd):


如果为空,则运行MySQL服务器或更改端口

问题在于旧版本的MySQL Connector/J与MySQL 8的兼容性。我只需要用最新版本升级SQL Connector版本


经过大量的努力,我终于找到了问题所在。

你让位于小环境,让我们甚至开始猜测出了什么问题。听起来你的mysql服务器没有运行。我的sql服务器正在运行。问题在于mysql连接器和java hibernate之间的兼容性。实际上,该版本的java中存在一个bug。之后我很努力地找到了实际问题。
sudo netstat -npl | grep 3306
netstat -aon | find /i "3306"