简体   繁体   English

错误:找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序

[英]ERROR: No suitable driver found for jdbc:mysql://localhost:3306/test

I am getting no suitable driver exception. 我没有合适的驱动程序异常。 Connection is not created. 未创建连接。

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>

This is my code and and iam facing the Same issue. 这是我的代码,并且iam面临相同的问题。

You need to add this property to the hibernate.cfg.xml 您需要将此属性添加到hibernate.cfg.xml

<property 
  name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

And you need to have mysql-connector-java jar at the class path. 并且您需要在类路径中具有mysql-connector-java jar

Your transaction code is not correct (you don't use rollback, for an example). 您的交易代码不正确(例如,您不使用回滚)。 Refer this for how to properly work with that. 请参阅此内容以了解如何正确使用该功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到适用于jdbc:mysql // localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql//localhost:3306/test 找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/test 发现此错误“没有找到适合 jdbc:mysql//localhost:3306/student 的驱动程序” - Found this error "No suitable driver found for jdbc:mysql//localhost:3306/student" JDBC JAVA找不到适合的驱动程序jdbc:mysql:// localhost:3306 / voting - JDBC JAVA No suitable driver found for jdbc:mysql://localhost:3306/voting 如何解决:找不到适合jdbc的驱动:mysql://localhost:3306/sampledb - How to solve: No suitable driver found for jdbc:mysql://localhost:3306/sampledb 找不到适用于jdbc:mysql:// localhost:3306 / jpa的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/ jpa 找不到适用于jdbc:mysql / localhost:3306 / world的驱动程序 - No suitable driver found for jdbc:mysql/localhost:3306/world Eclipse - Hibernate:没有为jdbc找到合适的驱动程序:mysql:// localhost:3306 / hibernatedb - Eclipse - Hibernate : No suitable driver found for jdbc:mysql://localhost:3306/hibernatedb 找不到适用于jdbc:mysql // localhost:3306 / demo的驱动程序吗?useSSL = false - No suitable driver found for jdbc:mysql//localhost:3306/demo?useSSL=false SQLException:找不到适用于jdbc:mysql:// localhost:3306 / dbname的驱动程序 - SQLException: No suitable driver found for jdbc:mysql://localhost:3306/dbname
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM