简体   繁体   中英

How to make Oracle JDBC connection and execute queries in Spring Boot?

I didn't get a clear picture on making a Oracle JDBC connection in Spring Boot and executing the queries. Can someone please help me or guide me regarding this issue?

First at all you will need the oracle jdbc driver as maven/gradle dependency. Oracle does not have its driver in the public repository. So you need to download the jdbc driver from oracle and install this jar into a maven dependency.

mvn install:install-file -Dfile=ojdbc7.jar  -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.1 -Dpackaging=jar

Or you can go to the oracle specific maven repository and get the stuff from there.

After that you are able to add this dependency to your pom.xml of your application.

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

On the https://start.spring.io/ website you can create a brand new application. For the start I would choose Web and JPA .

Now in the application.properties file you can set your jdbc configurations:

spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:yourUrl
spring.datasource.username=username
spring.datasource.password=password

After that you should be able to start and run the application.

For more you should read docs for Springs repositories , custom queries , custom entity manager

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM