J'essaie de créer des tables dans la base de données MySQL à l'aide d'Hibernate, mais je suis confronté au problème suivant : "Impossible d'ouvrir une connexion JDBC pour l'exécution DDL". J'ai saisi une URL de connexion valide et les fichiers jar requis, mais je ne parviens pas à créer une connexion avec la base de données. J'ai cherché de nombreuses solutions disponibles pour cela mais aucune ne fonctionne pour moi. Merci de me dire ce que je fais de travers.
Version d'Hibernate : hibernate-core-5.4.12.Final
Connecteur MySQL : 8.0.17
DBconn.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;
}
}
HbConnection.java
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"?>
"-//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.url">jdbc:mysql://localhost:3306/maxigodb</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping class="com.maxico.pojo.Login_data"/>
<mapping class="com.maxico.pojo.Agent_data"/>
<mapping class="com.maxico.pojo.Hotel_data"/>
<mapping class="com.maxico.pojo.HotelBooking_Details"/>
</session-factory>
erreur de console
WARN: HHH030006: Exception occurred when closing the Proxool pool
java.lang.NullPointerException
at org.hibernate.proxool.internal.ProxoolConnectionProvider.stop(ProxoolConnectionProvider.java:233)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.stopService(AbstractServiceRegistryImpl.java:390)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.destroy(AbstractServiceRegistryImpl.java:373)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.destroy(StandardServiceRegistryImpl.java:129)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.deRegisterChild(AbstractServiceRegistryImpl.java:423)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:468)
at com.maxico.test.HbConnection.getSession(HbConnection.java:20)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:303)
Feb 27, 2020 12:07:39 PM org.hibernate.service.internal.AbstractServiceRegistryImpl stopService
INFO: HHH000369: Error stopping service [class org.hibernate.proxool.internal.ProxoolConnectionProvider]
org.hibernate.HibernateException: HHH030006: Exception occurred when closing the Proxool pool
at org.hibernate.proxool.internal.ProxoolConnectionProvider.stop(ProxoolConnectionProvider.java:241)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.stopService(AbstractServiceRegistryImpl.java:390)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.destroy(AbstractServiceRegistryImpl.java:373)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.destroy(StandardServiceRegistryImpl.java:129)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.deRegisterChild(AbstractServiceRegistryImpl.java:423)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:468)
at com.maxico.test.HbConnection.getSession(HbConnection.java:20)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:303)
Caused by: java.lang.NullPointerException
at org.hibernate.proxool.internal.ProxoolConnectionProvider.stop(ProxoolConnectionProvider.java:233)
... 39 more
Feb 27, 2020 12:07:39 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Maxico] threw exception [An exception occurred processing [index.jsp] at line [182]
181: Session ses= null;
182: ses= HbConnection.getSession();
183: System.out.println("Email:" +user);
184: try {
185:
Stacktrace:] with root cause
java.sql.SQLException: The url cannot be null
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:660)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)
at org.hibernate.proxool.internal.ProxoolConnectionProvider.getConnection(ProxoolConnectionProvider.java:69)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180)
at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:43)
at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.getTablesInformation(DatabaseInformationImpl.java:120)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)
Fichiers JAR