9

I'm working with Spring Boot application and trying to access an Oracle database. Although it was successfully built, it gives the error below when I am trying to deploy in Kubernetes.

I changed the application.properties file and pom.xml file with below configurations:

application.properties

spring.datasource.url=jdbc:oracle:thin:@<IP>:1521:orcl
spring.datasource.username=<username>
spring.datasource.password=<password>
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver

POM file

 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-jdbc</artifactId>
 </dependency>

Exception

***************************
APPLICATION FAILED TO START
***************************
 Description:
 Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
     Property: driverclassname
    Value: oracle.jdbc.OracleDriver
    Origin: "driverClassName" from property source "source"
    Reason: Failed to load driver class oracle.jdbc.OracleDriver in either of 
            HikariConfig class loader or Thread context classloader
 Action:
 Update your application's configuration   
3
  • 2
    You need the OJDBC driver Commented Jan 22, 2019 at 9:47
  • Check my answer on spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver it should be driver.class-name Commented Jan 23, 2019 at 6:43
  • 3
    @Dhanushka - If the issue fixed, please select correct answer. It might be useful for others. Cheers Commented May 20, 2019 at 5:28

10 Answers 10

9

Maven dependency:

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc7</artifactId>
    <version>12.1.0</version>
</dependency>

application.properties file:

# Oracle settings
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe
spring.datasource.username=system
spring.datasource.password=password
spring.datasource.driver.class-name=oracle.jdbc.OracleDriver

Note: driver.class-name

Sometimes you may need to add

spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

to application.properties file (for Oracle 10).

Sign up to request clarification or add additional context in comments.

Comments

5

Add below dependency and repository in the pom.xml:

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

Also add the following properties in the application.properties:

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe(SID)
spring.datasource.username=system
spring.datasource.password=pw

Comments

1

Update the db driver in the file Application.yml to

spring.datasource.driver-class-name=oracle.jdbc.**driver**.OracleDriver or spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

3 Comments

Another inconsistency? spring.datasource.driver.class-name v/s spring.datasource.driver-class-name
Requests for clarification or further information from OP should go in a comment, not an answer. Please only post an answer if it actually answers the question.
By the way, I found the answers to my questions:use spring.datasource.driver-class-name=oracle.jdbc.OracleDriver for >Oracle 9i (no driver needed) However, if I unpack the ojdbc6.jar I see both classes there. And the correct attribute to use is spring.datasource.driver-class-name
1

I used implementation 'com.oracle:ojdbc7:12.1.0.2.0 gradle dependency.

Added below in the application.properties:

# hibernate configs
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect

# database details
spring.datasource.url=jdbc:oracle:thin:@//<host>:<port>/<database>
spring.datasource.username=<username>
spring.datasource.password=<password>
spring.datasource.driver.class-name=oracle.jdbc.OracleDriver

You can use different OracleDialect if it's not working for you.

For me above code is working without any issue.

Comments

0

You can check if the SpringBoot app example helps.

Comments

0

You just need to add these two dependencies in your pom.xml file and it will work fine:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <scope>runtime</scope>
</dependency>

Comments

0

Use this configuration in application.properties:

spring.jpa.show-sql=true

spring.h2.console.enabled=true
    
# Using SID
spring.datasource.url= jdbc:oracle:thin:@localhost:1521:ORCL
spring.datasource.username=SYSTEM   
spring.datasource.password=SYSTEM
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
    
# hibernate configs
spring.jpa.database-platform=org.hibernate.dialect.OracleDialect
spring.jpa.hibernate.ddl-auto=update 

Caution:

  1. org.hibernate.dialect.Oracle10gDialect has been deprecated.
  2. You need to check jdbc:oracle:thin:@localhost:1521:ORCL if the last part of this database URL is "ORCL" OR "XE". See below screenshot: screenshot of Oracle SQL Developer GUI with Select Database Connection modal

Comments

0

For Oracle DB,

Maven settings:

<dependency>
    <groupId>com.oracle.ojdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>19.3.0.0</version>
</dependency>

Properties settings:

spring.datasource.url=jdbc:oracle:thin:@172.16.10.12:1521/orcl11
spring.datasource.username=[username]
spring.datasource.password=[password]

Don't use

spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

Comments

0

You can use the Connection class in SpringBoot to establish Connection, also make sure that the port id, is correct, it will ease a lot of hardwork.

1 Comment

Thank you for your interest in contributing to the Stack Overflow community. This question already has a few answers—including at least one that has been validated by the community. It would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?
-1

You need to download Oracle JDBC driver jar file and add it into your classpath in order for your application to load oracle.jdbc.OracleDriver class.

Driver can be downloaded from here.

2 Comments

I already tried it in InteliJ. It successfully build it in IDE. But when I try to deploy it in kubernetes, it gives the error. please help
Are you creating a fat jar? If yes then you can include driver jar explicitly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.