Home > Back-end >  what is the best way to create session from java spring boot using oracle Database?
what is the best way to create session from java spring boot using oracle Database?

Time:06-08

I created user in oracle database and I am trying to create session but I find many ways in spring boot so what is the easy way if I want to create classe connections using the Username and Password ?

CodePudding user response:

You can jdbc template, spring data JDBC or spring data JPA, well depending on your use case.

If your data model is quite complex, you should avoid using the JDBC template as you will need to write prepared statements which can be cumbersome. JPA will allow you to use object-oriented programming principles and also will help you map the entities to your database columns.

For example, if you are going to use spring data JPA, you need to set the application properties as follows:

spring.datasource.type=oracle.oracleucp.jdbc.UCPDataSource
spring.datasource.oracleucp.connection-factory-class-name=oracle.jdbc.pool.OracleDataSource 
spring.datasource.oracleucp.sql-for-validate-connection=select * from dual 
spring.datasource.oracleucp.connection-pool-name=UcpPoolBooks 
spring.datasource.oracleucp.initial-pool-size=5 
spring.datasource.oracleucp.min-pool-size=5 
spring.datasource.oracleucp.max-pool-size=10

This would behind the scene create an Oracle Datasource. In this example, we are using Oracle Universal Connection Pooling. You can also use HikariCP which is quite popular.

check this out

  • Related