Spring无法加载JDBC驱动程序类错误

时间:2016-12-13 10:22:55

标签: java spring hibernate jdbc

我在spring jdbc javapoint

中执行spring jdbc示例时遇到以下错误
$ mv ~/.nvm /tmp/
$ export NVM_DIR="/tmp/.nvm"
$ nvm use --delete-prefix v6.9.1

Employee.java我修改了如下所有我从javapoint链接中获取的所有内容

 Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds' defined in class path resource [sjdbc1.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

的pom.xml

1.Employee.java
package com.pro.sjdbc1;

public class Employee {
    private int id;
    private String name;
    private float salary;
    // no-arg and parameterized constructors
    // getters and setters
    Employee(int id,String name,float salary){
        id=this.id;
        name=this.name;
        salary=this.salary;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public float getSalary() {
        return salary;
    }
    public void setSalary(float salary) {
        this.salary = salary;
    }

}

感谢。

1 个答案:

答案 0 :(得分:1)

您的类路径中没有Oracle JDBC驱动程序。您需要在POM文件中添加依赖项。

e.g。

<dependency>
 <groupId>com.oracle.jdbc</groupId>
 <artifactId>ojdbc7</artifactId>
 <version>x.xx</version>
</dependency>

请注意这是一个例子。您需要添加正确的驱动程序版本。 您可能还需要添加适当的Oracle Maven存储库(https://maven.oracle.com)。 AFAIK Oracle JDBC驱动程序不在标准的Maven中央存储库中。

See here for how to add the maven Oracle repository