我正在尝试使用休眠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();}我已经检查了数据库的用户名和密码以及所有正确的东西,但是我仍然遇到此错误。
2 回答
![?](http://img1.sycdn.imooc.com/5333a1bc00014e8302000200-100-100.jpg)
素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
如果您使用的是Mysql 5.x,请使用
org.hibernate.dialect.MySQL5Dialect
作为方言。
和/或
<property
name="hibernate.connection.url">"jdbc:mysql://localhost:3306/moathdb" >
在此处删除行情。
您的字符串如下所示:
property
name="hibernate.connection.url">jdbc:mysql://localhost:3306/moathdb>
它会工作。
添加回答
举报
0/150
提交
取消