I want to get data from oracle database in spring boot, but I dont want to use JPA. Can you give me an example, how I should do it? Thank you.
Using a Database without JPA in Spring-Boot you can use the JDBC starter of Spring-Boot.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
For Oracle you also need to use the JDBC driver. For example this one:
<dependency>
<groupId>oracle.jdbc</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
<classifier>jdk17</classifier>
</dependency>
In the application.properties file you have to configure the datasource:
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
This is all you need for the configuration. To make a select to the database you have to autowire JdbcTemplate in any of your spring bean classes.
@Component
public class DataDao {
private final JdbcTemplate jdbcTemplate;
public DataDao(JdbcTemplate jdbcTemplate) {
super();
this.jdbcTemplate = jdbcTemplate;
}
After autowiring the jdbcTemplate you are able to query the database:
jdbcTemplate.query(yourQuery, RowMapper<?>);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With