gpt4 book ai didi

java - 调用 Driver#connect 时出错,无法创建与数据库服务器的连接

转载 作者:行者123 更新时间:2023-11-29 16:14:03 26 4
gpt4 key购买 nike

Mar 05, 2019 10:12:28 AM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Mar 05, 2019 10:38:45 AM <clinit>
INFO: HHH000206: hibernate.properties not found
//hibernate class
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();

private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new Configuration().configure().buildSessionFactory();
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}

}

java.lang.ExceptionInInitializerError

Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

<?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.password">***</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/foot?autoReconnect=true&amp;=utf-8&amp;useUnicode=true&amp;connectionCollation=utf8_unicode_ci&amp;characterSetResults=utf8</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">update </property>

<mapping class="vn.myclass.core.persistence.entity.MemberEntity" />
<mapping class="vn.myclass.core.persistence.entity.RoleEntity" />
<mapping class="vn.myclass.core.persistence.entity.ProductEntity" />
<mapping class="vn.myclass.core.persistence.entity.CommentEntity" />
</session-factory>
</hibernate-configuration>

最佳答案

我修复了位于驱动程序连接器中的问题,因为 mysql 版本 8.0 支持驱动程序连接器/j 5.5 及更高版本

关于java - 调用 Driver#connect 时出错,无法创建与数据库服务器的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54994794/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com