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

David Dai picture David Dai · Jul 28, 2013 · Viewed 86.5k times · Source

I wonder if any one could help me with this. I encountered an issue when I tried writing code with Spring JDBC. When I ran the server, I got the message like I mentioned in the title. I have google it and someone said that you should import ojdbc.jar. However, I have already imported it. Here comes my code:

<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:@192.168.0.13:1521/orcl" />
    <property name="username" value="Hibernate" />
    <property name="password" value="123456" />
    </bean>

</beans>

Please kindly suggest if I have done something wrong. Many thanks in advance.

Answer

Jagadeesh picture Jagadeesh · Feb 8, 2015

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>