gpt4 book ai didi

java - Netbeans 7.1 Hibernate 逆向工程向导找不到数据库驱动程序

转载 作者:搜寻专家 更新时间:2023-11-01 02:52:13 26 4
gpt4 key购买 nike

我目前正在尝试完成此 netbeans + hibernate + JavaSE 教程 ( http://netbeans.org/kb/docs/java/hibernate-java-se.html )。一切都很好,但是在创建 hibernate.cfg.xml 之后,当谈到应该应用逆向工程的部分时,逆向工程向导告诉我一些奇怪的消息:

"The database drivers are not added to the project classpath." 
"Go to project properties to add database library.".

这有点奇怪,因为 hibernate.cfg.xml 是由 netbeans 生成的。我已经用 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>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sakila</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">apassword</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
</session-factory>
</hibernate-configuration>

最佳答案

在hibernate.cfg.xml中添加这行代码

<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/DATABASE_NAME</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"/>
</session-factory>

关于java - Netbeans 7.1 Hibernate 逆向工程向导找不到数据库驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9104115/

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