Java org.hibernate.exception.jdbconnectionexception:无法打开JDBC连接以执行DDL
我试图使用hibernate在MySQL数据库中创建表,但我面临一个问题“无法打开JDBC连接以执行DDL”。我输入了有效的连接URL和必需的jar文件,但无法创建与数据库的连接。 我搜索了很多解决方案,但都不适合我。请告诉我我做错了什么 Hibernate版本:Hibernate-core-5.4.12.Final MySQL连接器:8.0.17 DBconn.javaJava org.hibernate.exception.jdbconnectionexception:无法打开JDBC连接以执行DDL,java,mysql,hibernate,Java,Mysql,Hibernate,我试图使用hibernate在MySQL数据库中创建表,但我面临一个问题“无法打开JDBC连接以执行DDL”。我输入了有效的连接URL和必需的jar文件,但无法创建与数据库的连接。 我搜索了很多解决方案,但都不适合我。请告诉我我做错了什么 Hibernate版本:Hibernate-core-5.4.12.Final MySQL连接器:8.0.17 DBconn.java public class Dbconn { static Connection con=null; public stat
public class Dbconn {
static Connection con=null;
public static Connection connect() throws ClassNotFoundException, SQLException
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/maxigodb","root","root");
//System.out.println("db connected");
return con;
}
}
public class HbConnection {
static Session ses=null;
public static Session getSession()
{
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build();
Metadata meta = new MetadataSources(ssr).getMetadataBuilder().build();
SessionFactory factory = meta.getSessionFactoryBuilder().build();
ses = factory.openSession();
return ses;
}
}
HbConnection.java
public class Dbconn {
static Connection con=null;
public static Connection connect() throws ClassNotFoundException, SQLException
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/maxigodb","root","root");
//System.out.println("db connected");
return con;
}
}
public class HbConnection {
static Session ses=null;
public static Session getSession()
{
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build();
Metadata meta = new MetadataSources(ssr).getMetadataBuilder().build();
SessionFactory factory = meta.getSessionFactoryBuilder().build();
ses = factory.openSession();
return ses;
}
}
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
JAR文件
我认为你应该删除引号:
jdbc:mysql://localhost:3306/maxigodb“我解决了这个问题 出现此问题是因为我添加了两个jar文件hibernate-proxool-5.4.12.Final和proxool-0.8.3。
我删除了hibernate-proxool-5.4.12.Final,之后我可以建立与数据库的连接。请通过编辑对您的答案添加一些解释,以便其他人可以从中学习