繁体   English   中英

休眠 - 无法建立 JDBC 连接 [jdbc:mysql//localhost:3306/hibernatedb

[英]Hibernate - Unable to make JDBC Connection [jdbc:mysql//localhost:3306/hibernatedb

我正在尝试使用 hibernate 5.2.10 版本创建一个基本的休眠应用程序。 当我运行它时,它说

org.hibernate.HibernateException: Unable to make JDBC Connection [jdbc:mysql//localhost:3306/hibernatedb]

休眠.cfg.xml:

<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.url">jdbc:mysql//localhost:3306/hibernatedb</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">root</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
    <property name="hibernate.cache.use_query_cache">true</property>
    <property name="hibernate.hbm2ddl.auto">udpate</property>
    <mapping class="com.chandu.app.model.UserDetails"/>
</session-factory>

主类:

public class HibernateTest {

public static void main(String[] args) {
    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    UserDetails user = getUserObject();
    session.save(user);
    session.getTransaction().commit();
    session.clear();
}

private static UserDetails getUserObject() {
    UserDetails user = new UserDetails();
    user.setUserName("Test User");

    return user;
}

安慰:

控制台输出

代码结构:

在此处输入图像描述

我浏览了一些论坛,但找不到相同的解决方案。 谢谢您的帮助!

jdbc:mysql//localhost:3306/hibernatedb

在“mysql”之前和之后使用冒号( :

jdbc:mysql://localhost:3306/hibernatedb

暂无
暂无

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

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