【问题标题】:No JDBC Driver class was specified by property hibernate.connection.driver_class 2 [closed]属性 hibernate.connection.driver_class 2 未指定 JDBC 驱动程序类 [关闭]
【发布时间】:2015-06-12 12:37:28
【问题描述】:

我正在学习本教程“Java RESTful Web Service 使用 MySQL 和 Hibernate 访问数据库”

https://youtu.be/Du_-ge7OO3s

但我收到了这个错误

警告 [http-nio-8084-exec-2] org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure HHH000148: 属性 hibernate.connection.driver_class 未指定 JDBC 驱动程序类

WARN [http-nio-8084-exec-2] org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure HHH000342:无法获得查询元数据的连接:没有找到适合 jdbc:mysql://localhost 的驱动程序:3306/testws

我的文件是 HibernateUtil.java

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml) 
            // config file.
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception. 
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

hibernate.cfg.xml

<?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>
    <!-- Opciones de Conexión a Base de Datos -->
    <property name="hibernate.conecction.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/testws</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">****</property>
    <!-- Dialecto SQL -->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <!-- Escribe todas las declaraciones SQL ejecutadas  a stdout-->
    <property name="show_sql">true</property>
    <!-- Nombres de clases entidad-->
    <mapping class="com.mycompany.testws.model.Person"/>
  </session-factory>
</hibernate-configuration>

还有 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycompany</groupId>
    <artifactId>TestWS</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>TestWS</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
    <repository>
        <id>org.jboss.resteasy</id>
        <url>http://repository.jboss.org/maven2/</url>
    </repository>
    </repositories>

        <dependencies>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-web-api</artifactId>
                <version>7.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jaxrs</artifactId>
                <version>2.3.6.Final</version>
            </dependency>
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jaxb-provider</artifactId>
                <version>2.3.6.Final</version>
            </dependency>
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jettison-provider</artifactId>
                <version>2.3.6.Final</version>
            </dependency>

            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.34</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>4.2.2.Final</version>
            </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

我将搜索可能的错误,但找不到解决方案,我在此路径中有驱动程序

C:\TestWS\target\TestWS-1.0-SNAPSHOT\WEB-INF\lib\mysql-connector-java-5.1.34.jar

请帮帮我,谢谢

【问题讨论】:

    标签: java mysql hibernate netbeans jdbc


    【解决方案1】:

    您在配置文件中似乎拼写错误。

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

    “连接”应该是连接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-24
      • 2013-09-15
      • 1970-01-01
      相关资源
      最近更新 更多