简体   繁体   English

未找到指定的 JDBC 驱动程序 com.mysql.jdbc.Driver 类

[英]Specified JDBC Driver com.mysql.jdbc.Driver class not found

I am using eclipse juno and hibernate 4.1.6 , mysql connector 5.1.24 , jboss 7.1.1 .我正在使用eclipse junohibernate 4.1.6mysql 连接器 5.1.24jboss 7.1.1

I tried this and this (as a module).我试过这个这个(作为一个模块)。

I have the connector JAR in WEB-INF/lib folder, and I also tried once without it.我在WEB-INF/lib文件夹中有连接器 JAR,我也试过一次没有它。 Everything failed.一切都失败了。 I don't know anymore how I can solve this problem.我不知道我该如何解决这个问题。 The whole stack trace:整个堆栈跟踪:

18:35:44,284 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) Error creating Session: org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver com.mysql.jdbc.Driver class not found

The connector is an the class path, it's in the Maven Dependencies Library.连接器是一个类路径,它在 Maven 依赖库中。 I put it in the lib folder and in the System Library...nothing works.我把它放在 lib 文件夹和系统库中......没有任何效果。

public class HibernateUtil {

private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;

static
{
    try
    {
        Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
        serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    }
    catch (HibernateException he)
    {
        System.err.println("Error creating Session: " + he);
        throw new ExceptionInInitializerError(he);
    }
}

Check in your hibernate.cfg.xml file that you have correctly specified the driver class and the dialect :检查您已正确指定driver classdialect hibernate.cfg.xml文件:

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

(these are properties of the <session-factory> ) (这些是<session-factory>属性)

Then, simply build your Session Factory:然后,只需构建您的会话工厂:

sessionFactory = new Configuration().configure().buildSessionFactory();

If the application still does not see your Maven dependency for the connector, try doing a clean install, and after it check in the list of libraries for your project that the MySQL Connector appears there.如果应用程序仍然看不到连接器的 Maven 依赖项,请尝试进行全新安装,然后检查项目的库列表中是否出现MySQL Connector

Please check your mysql connector version is compatible with mysql db installed on your system.请检查您的 mysql 连接器版本是否与系统上安装的 mysql db 兼容。 eg mysql connector version 5.1.26 is compatible with mysql 5.6.25 while 5.1.34 is not.例如,mysql 连接器版本 5.1.26 与 mysql 5.6.25 兼容,而 5.1.34 则不兼容。

尝试将连接器添加到构建路径作为外部 jar 或,创建一个 lib 文件夹并将连接器 jar 放入其中,然后Add Library到您的构建路径并提供该连接器 lib 文件夹路径。

Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder().applySettings(configuration.getProperties());
sessionFactory = configuration.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
// end of static block

public static SessionFactory getSessionFactory() {
    return sessionFactory;
}

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

相关问题 找不到类com.mysql.jdbc.Driver - Class not found com.mysql.jdbc.Driver 创建会话时出错:org.hibernate.HibernateException:找不到指定的JDBC驱动程序com.mysql.jdbc.Driver类 - Error creating Session: org.hibernate.HibernateException: Specified JDBC Driver com.mysql.jdbc.Driver class not found 找不到com.mysql.jdbc.Driver的类 - class not found exception for com.mysql.jdbc.Driver com.mysql.jdbc.driver类未找到异常 - com.mysql.jdbc.driver class not found exception 无法加载 JDBC 驱动程序类 [com.mysql.jdbc.Driver] - Could not load JDBC driver class [com.mysql.jdbc.Driver] 使用Hibernate的问题 - 找不到JDBC驱动程序类:com.mysql.jdbc.Driver - Problems using Hibernate - JDBC Driver class not found: com.mysql.jdbc.Driver 找不到驱动程序:[com.mysql.jdbc.Driver]播放框架 - Driver not found: [com.mysql.jdbc.Driver] play framework 无法加载驱动程序 class com.mysql.Z84BEFFD3A0D49636A58CE6080CAA87C7 - Failed to load driver class com.mysql.jdbc.Driver 无法加载驱动程序 class:com.mysql.jdbc.Driver Spring - Cannot load driver class: com.mysql.jdbc.Driver Spring 无法为连接URL&#39;jdbc:mysql // localhost:3306 /创建类&#39;com.mysql.jdbc.Driver&#39;的JDBC驱动程序 - Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'jdbc:mysql//localhost:3306/
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM