Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set oracle db connection timeout in spring Boot application

I have to set Oracle DB connection timeout in Spring Boot application. How can I set it?

In WebLogic server, I am able to set using following properties:

oracle.jdbc.ReadTimeout=50000
oracle.net.CONNECT_TIMEOUT=20000 
like image 256
Raj Avatar asked Sep 01 '25 06:09

Raj


1 Answers

You can set it as:

    @Bean
    public HikariDataSource dataSource() {

        HikariDataSource ds = new HikariDataSource();
        ds.setDriverClassName(springDatasourceDriverClassName);
        ds.setJdbcUrl(springDatasourceUrl);
        ds.setUsername(springDatasourceUsername);
        ds.setPassword(springDatasourcePassword);
        ds.setDataSourceProperties(oracleProperties());

        return ds;
    }

    Properties oracleProperties() {
        Properties properties = new Properties();

        properties.put("oracle.net.CONNECT_TIMEOUT", 10000);
        properties.put("oracle.net.READ_TIMEOUT", 10000);
        properties.put("oracle.jdbc.ReadTimeout", 10000);

        return properties;
    }

And if you do not want to configure a bean for the DataSource(which is what most people will do), you can configure the network timeout properties in application.properties:

spring.datasource.hikari.data-source-properties.oracle.net.CONNECT_TIMEOUT=10000
spring.datasource.hikari.data-source-properties.oracle.net.READ_TIMEOUT=10000
spring.datasource.hikari.data-source-properties.oracle.jdbc.ReadTimeout=10000
like image 64
jumping_monkey Avatar answered Sep 02 '25 20:09

jumping_monkey