gpt4 book ai didi

java - 当我使用 Hibernate Config 进行反向工程时出现此错误 : -"java.sql.SQLException: No suitable driver found for".。我的数据库

转载 作者:行者123 更新时间:2023-11-30 21:27:35 25 4
gpt4 key购买 nike

我正在尝试使用 Hibernate Configuration 和 eclipse IDE 对我的简单 MYSQL DB 进行工程化改造。但出现以下错误。

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3307/client1_db

我遇到过类似的问题。这是一个 Marven Web 项目,我可以看到 MYSQL_connector_java_5.1.34.jar 在 Marven Dependencies 库下。有人建议“找不到合适的驱动程序”意味着驱动程序正在加载,但数据库连接存在问题。我尝试连接到本地主机,数据库是使用 MySQL Workbench 创建的,并且可以访问。我什至尝试使用 myphp admin 并且可以访问数据库。

hibernate.cfg.xml 文件

    <?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/bookshop</property>
<property name="connection.username">root</property>
<property name="connection.password">password</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop the existing tables and create new one -->
<property name="hbm2ddl.auto">create</property>

</session-factory>
</hibernate-configuration>

然后我尝试使用不同的服务器端口 3307,如下所示。仍然是同样的错误。

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3307/client1_db</property>
<property name="connection.username">root</property>
<property name="connection.password">password</property>

完整的错误信息

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3307/client1_db
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:189)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:173)
at org.hibernate.cfg.reveng.dialect.AbstractMetaDataDialect.getConnection(AbstractMetaDataDialect.java:121)
at org.hibernate.cfg.reveng.dialect.AbstractMetaDataDialect.getMetaData(AbstractMetaDataDialect.java:60)
at org.hibernate.cfg.reveng.dialect.AbstractMetaDataDialect.caseForSearch(AbstractMetaDataDialect.java:163)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getTables(JDBCMetaDataDialect.java:22)
at org.hibernate.cfg.reveng.JDBCReader.processTables(JDBCReader.java:476)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:74)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.tools.hibernate.runtime.common.Util.invokeMethod(Util.java:43)
at org.jboss.tools.hibernate.runtime.common.AbstractJDBCReaderFacade.readDatabaseSchema(AbstractJDBCReaderFacade.java:44)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter$2.execute(LazyDatabaseSchemaWorkbenchAdapter.java:132)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.readDatabaseSchema(LazyDatabaseSchemaWorkbenchAdapter.java:124)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.getChildren(LazyDatabaseSchemaWorkbenchAdapter.java:64)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:104)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:219)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

hibernate 配置截图

enter image description here

包探索

enter image description here

最佳答案

关于java - 当我使用 Hibernate Config 进行反向工程时出现此错误 : -"java.sql.SQLException: No suitable driver found for".。我的数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58127541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com