gpt4 book ai didi

java - Hibernate - 无法加载请求的类 : org. mariadb.jdbc.Driver

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

所以我的问题非常基本。我只是运行一个简单的 hibernate Web 应用程序,它将一个新条目发送到我的 SQL MariaDB。当我运行该应用程序时,我收到一条错误消息,指出无法加载请求的类。没有意义的是我的库中有 .jar 文件,而我的其他测试文件运行良好。对于这个项目,我使用 Intellij IDEA。

hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- JDBC Database connection settings -->
<property name="connection.driver_class">com.mariadb.jdbc.Driver</property>
<property name="connection.url">jdbc:mariadb://localhost:3306/hb_student_tracker</property>
<property name="connection.username">hbstudent</property>
<property name="connection.password"></property>

<!-- JDBC connection pool settings ... using built-in test pool -->
<property name="connection.pool_size">1</property>

<!-- Select our SQL dialect -->
<property name="dialect">org.hibernate.dialect.MariaDB53Dialect</property>

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

<!-- Set the current session context -->
<property name="current_session_context_class">thread</property>

</session-factory>

创建学生演示

import com.luv2code.hibernate.demo.entity.Student;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class CreateStudentDemo {

public static void main(String[] args) {

//create session factory
SessionFactory factory = new Configuration()
.configure("hibernate.cfg.xml")
.addAnnotatedClass(Student.class)
.buildSessionFactory();
// create session
Session session = factory.getCurrentSession();

try {
// create a student object
System.out.println("Creating new student object...");
Student tempStudent = new Student(
"Paul", "Wall", "paul@luv2code.com");

// start a transaction
session.beginTransaction();

// save the student object
System.out.println("Saving the student...");
session.save(tempStudent);

// commit transaction
session.getTransaction().commit();

System.out.println("Done!");
}
finally {
factory.close();
}
}

enter image description here

我认为问题出在 hibernate.xml 文件上。任何帮助将不胜感激!

最佳答案

com.mariadb.jdbc.Driver

无法加载请求的类:org.mariadb.jdbc.Driver

关于java - Hibernate - 无法加载请求的类 : org. mariadb.jdbc.Driver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51218846/

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