簡體   English   中英

錯誤:找不到適用於jdbc:mysql:// localhost:3306 / test的驅動程序

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

我沒有合適的驅動程序異常。 未創建連接。

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>

這是我的代碼,並且iam面臨相同的問題。

您需要將此屬性添加到hibernate.cfg.xml

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

並且您需要在類路徑中具有mysql-connector-java jar

您的交易代碼不正確(例如,您不使用回滾)。 請參閱此內容以了解如何正確使用該功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM