18

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.

David Dai
  • 1,095
  • 2
  • 8
  • 11
  • 1
    You need to make sure that ojdbc.jar is in your CLASSPATH when application is running. For example, if you are creating a web app - ojdbc.jar should be present in WEB-INF/lib of your WAR file. – Sergey Makarov Jul 28 '13 at 12:21
  • @SergeyMakarov Hi Sergey, thank you for your quick response. However, I am just testing it in MyEclipse... – David Dai Jul 28 '13 at 12:37
  • You need to setup build path for your Eclipse project, this may help - http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java) – Sergey Makarov Jul 28 '13 at 13:16
  • 1
    @SergeyMakarov Thank you again for your reply. However, when I replaced the class content with this: "org.apache.commons.dbcp.BasicDataSource" it works well. Pretty strange. – David Dai Jul 28 '13 at 22:05
  • are you using any build tools like maven ? – JToddler Apr 16 '14 at 09:31

9 Answers9

11

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>
Jagadeesh
  • 2,730
  • 6
  • 30
  • 45
  • @jagadesh, isn't oracle jdbc.jar covered under oracle license and that's why it is not on maven? Also, will I come under trouble if I'm using this for office work? – Kainix Nov 14 '19 at 07:30
  • @kainix, yes you did have issues using in work place. You still have an option to have it installed as a maven artifact to your repo and use it. However, it come back to the same question that is it a right way of having access to these license jars? That I can't have an answer for. – Jagadeesh Mar 23 '20 at 12:59
6

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>
</dependency>

Then do :

mvn install:install-file \
-Dfile=path/to/ojdbc6.jar \
-DgroupId=com.oracle \
-DartifactId=ojdbc6 \
-Dversion=11.2.0 \
-Dpackaging=jars
Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29
Dhana
  • 694
  • 13
  • 18
3

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.

user3260035
  • 115
  • 1
  • 5
1

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>
Roy Scheffers
  • 3,832
  • 11
  • 31
  • 36
Jairo Martínez
  • 465
  • 5
  • 9
1

Just copy ojdbc6.jar into tomcat/lib folder as in a picture below. example tomcat/lib/

1

If you are using Maven as your build tool, then add this below dependency. Make sure you have the correct version of ojdbcXX.jar file corresponding to the database version. For me, I have an Oracle 11g database, hence I am using ojdbc6.jar.

Step 1) Add dependency

<dependency>
   <groupId>com.oracle</groupId>
   <artifactId>ojdbc</artifactId>
   <version>6</version>
   <scope>system</scope>
   <systemPath>C:\Users\AkhileshPC\Downloads\ojdbc6.jar</systemPath>
</dependency>

Step 2) Install the ojdbcXX.jar in your Maven local repository.

Command > mvn install:install-file "-Dfile =Downloads\ojdbc6.jar" "-DgroupId=com.oracle" "-DartifactId=ojdbc6" "-Dversion=11.2.0.1" "-Dpackaging=jar"

Setting up maven local repository image

Step 3) Make sure your ojdbcXX.jar file is available in the WEB-INF\lib folder of the corresponding project in the .metadata folder.

My case:

C:\Users\AkhileshPC\JavaSpring\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\1007_Spring_Mvc_App_Crud\WEB-INF\lib

web-inf folder path Image

Once all three of these steps are completed, the issue should be resolved.

0

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)

Vy Do
  • 46,709
  • 59
  • 215
  • 313
0

I resolved it in InteliJ like this:

File -> Project Structure -> Libraries -> click on '+' (add new) -> point to the ojdbc.jar path under file system (previously downloaded manually or using some build tool)

Filip
  • 2,244
  • 2
  • 21
  • 34
0

I tried to use idea add ojdbc to lib ,but it is not valid.

My final solution is to add ojdbc.jar to tomcat lib dir then restart it.

No fatal error

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
Thomas
  • 1