Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to oracle database using spring boot

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

 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   
like image 651
Dhanushka Sampath Avatar asked Dec 18 '22 19:12

Dhanushka Sampath


2 Answers

Maven dependency:

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

application.yml 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.yml file (for Oracle 10).

like image 137
smilyface Avatar answered Jan 02 '23 07:01

smilyface


Add below dependency and repository in the pom

<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
like image 30
Abdullah Imran Avatar answered Jan 02 '23 08:01

Abdullah Imran