尝试使用eclipse和hibernate 5连接到mysql数据库

我正在尝试使用休眠5连接到mysql,并且在控制台上收到此错误。


Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)

at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)

at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)

我已经尝试了所有与此相关的stackoverflow问题,但无法解决。

这是实体类:


import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.Id;


@Entity(name = "user_details")

public class UserDetails {


@Id

@Column(name = "id")

private int userId;

@Column(name = "user_name")

private String userName;


public int getUserId() {

    return userId;

}


public void setUserId(int userId) {

    this.userId = userId;

}


public String getUserName() {

    return userName;

}


public void setUserName(String userName) {

    this.userName = userName;

}


}

这是主要方法:


public static void main(String[] args) {


    UserDetails userDetails = new UserDetails();

    userDetails.setUserId(1);

    userDetails.setUserName("First User");


    SessionFactory sessionFactory = new 

    Configuration().configure().buildSessionFactory();

    Session session = sessionFactory.openSession();

    session.beginTransaction();

    session.save(userDetails);

    session.getTransaction().commit();

    session.close();


}

我已经检查了数据库的用户名和密码以及所有正确的东西,但是我仍然遇到此错误。


偶然的你
浏览 179回答 2
2回答

素胚勾勒不出你

如果您使用的是Mysql 5.x,请使用org.hibernate.dialect.MySQL5Dialect&nbsp;作为方言。和/或&nbsp;<property&nbsp;name="hibernate.connection.url">"jdbc:mysql://localhost:3306/moathdb" >&nbsp;在此处删除行情。您的字符串如下所示:property&nbsp;name="hibernate.connection.url">jdbc:mysql://localhost:3306/moathdb>它会工作。

jeck猫

您可以尝试删除hibernate.connection.url值中的引号。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java