Java 错误:未找到适合jdbc的驱动程序:mysql://localhost:3306/test
我没有得到合适的司机例外。未创建连接Java 错误:未找到适合jdbc的驱动程序:mysql://localhost:3306/test,java,mysql,hibernate,Java,Mysql,Hibernate,我没有得到合适的司机例外。未创建连接 package org.srtmun.student.dao.impl; import javax.transaction.Transaction; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.srtmun.student.dao.RegestrationDAO; im
package org.srtmun.student.dao.impl;
import javax.transaction.Transaction;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.srtmun.student.dao.RegestrationDAO;
import org.srtmun.student.hibernateplugin.HibernatePlug;
import org.srtmun.student.model.Registration;
public class RegistrationDaoImpl implements RegestrationDAO{
public void addStudent(Registration register) {
System.out.println("RegistrationDaoImpl class1");
SessionFactory factory = HibernatePlug.getFactory();
System.out.println("1");
Session session=factory.openSession();
org.hibernate.Transaction tx=session.beginTransaction();
session.save(register);
tx.commit();
session.close();
}
}
<?xml version='1.0' encoding='utf-8'?>
<!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>
<property name="hibernate.connection.password">123</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="Registration.hbm.xml" />
</session-factory>
</hibernate-configuration>
package org.srtmun.student.dao.impl;
导入javax.transaction.transaction;
导入org.hibernate.Session;
导入org.hibernate.SessionFactory;
导入org.hibernate.cfg.Configuration;
导入org.srtmun.student.dao.RegestrationDAO;
导入org.srtmun.student.hibernateplugin.HibernatePlug;
导入org.srtmun.student.model.Registration;
公共类RegistrationDaoImpl实现RegestrationDAO{
公立学校学生(注册处){
System.out.println(“RegistrationDaoImpl class1”);
SessionFactory=HibernatePlug.getFactory();
系统输出打印项次(“1”);
Session Session=factory.openSession();
org.hibernate.Transaction tx=session.beginTransaction();
会话。保存(注册);
tx.commit();
session.close();
}
}
123
jdbc:mysql://localhost:3306/test
根
org.hibernate.dialogue.mysqldialogue
这是我的代码,我和我面临同样的问题。您需要将此属性添加到
hibernate.cfg.xml
<property
name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
com.mysql.jdbc.Driver
你需要在类路径上有
您的事务代码不正确(例如,您没有使用回滚)。请参阅如何正确使用它。您的驱动程序在哪里?