Spring JDBC Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

拥有回忆 提交于 2019-11-29 13:12:25

Make sure that you have ojdbc.jar gets added into your class path. If you want, you can also double check it by opening .classpath file and look for ojdbc.jar entry. If you don't have it, download it from the the maven repo as mentioned below:

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.3</version>
        </dependency>
.......

    <repositories>
        <repository>
            <id>codelds</id>
            <url>https://code.lds.org/nexus/content/groups/main-repo</url>
        </repository>
    </repositories>

I just put ojdbc6.jar in apache tom cat installation directory in lib directory

D:\TOOLS\apache tomcat server\Tomcat 8.0\lib

It solved my problem.

Download the ojdbc jar from here

put ojdb6.jar in some folder in your project (let's use lib).

<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>11.2.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/ojdbc6.jar</systemPath>

Then do mvn install:install-file -Dfile=path/to/ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

Try

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value="jdbc:oracle:thin:schema_name/123456@192.168.0.13:1521:orcl" />
    <property name="username" value="Hibernate" />
    <property name="password" value="123456" />
    </bean>

</beans>

If you use Spring Boot 2 (I am using Spring Boot 2.0.4.RELEASE, Oracle database 12c), application.properties

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:schema_name/123456@192.168.0.13:1521:xe
spring.datasource.username=Hibernate
spring.datasource.password=123456

(You must have ojdbc7.jar in classpath)

Jairo Martínez

In my case the problem was setting the scope to runtime:

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>7.0.0.jre8</version>
    <scope>runtime</scope>
</dependency>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!