0

I have googled and found lots of documents and web pages saying that I should set oracle.net.ns.SQLnetDef.TCP_CONNTIMEOUT_STR to 3 seconds. I was unable to locate an example of how exactly to do that.

Is it a system level property that I can set with -Doracle.net.ns.SQLnetDef.TCP_CONNTIMEOUT_STR=3 or what? A properties file? A Spring config example?

I have a plain java application with the ojdbc.jar in the classpath. Beans are configured/wired using Spring xml.

<bean id="myDataSource" destroy-method="close"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${my.jdbc.driverClassName}" />
    <property name="url" value="${my.jdbc.url}" />

    <!-- cut -->
</bean>
hidralisk
  • 706
  • 6
  • 18

2 Answers2

1

To set oracle connection timeout at the socket level for basicdatasource

1) use latest basicdatasource -> commons-dbcp-1.4.jar

2) for jdbcdriver version > 10.1.0.5

 add property &ltproperty name="connectionProperties" value="oracle.jdbc.ReadTimeout=20000"/>

or for jdbcdriver version < 10.1.0.5

add &ltproperty name="connectionProperties" value="oracle.net.READ_TIMEOUT=20000"/>
user518066
  • 1,277
  • 3
  • 23
  • 35
0

Try and set this property for the BasicDataSource bean:

<property name="connectionProperties" value="oracle.net.CONNECT_TIMEOUT=3000" />

Reference: bottom of https://forums.oracle.com/thread/867795

Jukka
  • 4,583
  • 18
  • 14
  • your suggestion does not work, at least not in Spring 3.1 Did it work for you? the page you referring to is using CustomOracleDataSource class – hidralisk Sep 23 '13 at 04:18
  • The datasource type should not matter, the property is passed to the underlying JDBC driver. How exactly did it not work? AFAIK this property sets the connect timeout for establishing DB connections so did you try and connect to an unresponsive DB host? – Jukka Sep 23 '13 at 06:23
  • Connection timeout is different from socket read timeout. oracle.net.CONNECT_TIMEOUT may work only for Connection timeout. Check this: https://stackoverflow.com/questions/7360520/connectiontimeout-versus-sockettimeout – Srini Karthikeyan Nov 29 '18 at 12:43