4

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 

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

Any idea for redshift db connection timeout?
Hi @Nobita, Redshift is just PostgreSQL. This will work spring.datasource.hikari.connectionTimeout=10000.
-1

Try this spring.jpa.properties.hibernate.c3p0.timeout 5000 if you are using spring data jpa

1 Comment

The timeout for the application to acquire a connection(from the connection pool) has nothing to do with the JDBC/connect timeout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.