WLST script to set the JDBC Connection timeout properties in WebLogic server
By: Albin Issac
Tags: Programming, Oracle, Servers, Software Development, Weblogic

WLST script to set the JDBC Connection timeout properties in WebLogic server Albin Issac Follow Jun 19 · 2 min read

There are different timeout properties in the JDBC connection, this tutorial explains the approach to set some of the important JDBC Connection timeout properties in WebLogic server through WLST script.

Inactive Connection Timeout

The number of inactive seconds on a reserved connection before WebLogic Server reclaims the connection and releases it back into the connection pool.

You can use the Inactive Connection Timeout feature to reclaim leaked connections — connections that were not explicitly closed by the application.

Connection Reserve Timeout

The number of seconds after which a call to reserve a connection from the connection pool will timeout.

When set to 0, a call will never timeout.

When set to -1, a call will timeout immediately.

Statement Timeout

The time after which a statement currently being executed will time out.

A value of -1 disables this feature.

A value of 0 means that statements will not time out.

oracle.jdbc.ReadTimeout

The property oracle.jdbc.ReadTimeout helps to set read timeout while reading from the socket.

oracle.net.READ_TIMEOUT for jdbc versions < 10.1.0.5 oracle.jdbc.ReadTimeout for jdbc versions >=10.1.0.5

oracle.net.CONNECT_TIMEOUT

The property oracle.net.CONNECT_TIMEOUT helps to set the login time out in Oracle.

WLST Script

The below WLST script will help us to set the JDBC connection timeout properties

SetJDBCTimeoutProperties.py

def setJDBCTimeoutProperties():

dsName='CRM6EAIReference'

edit()

startEdit()



server='AdminServer'

cd("Servers/"+server)

target=cmo



print '========================================='

print 'Setting the timeout properties for DataSource....'

print '========================================='



cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName)

#cmo.destroyProperty(getMBean('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName+'/Properties/oracle.net.CONNECT_TIMEOUT'))

cmo.createProperty('oracle.net.CONNECT_TIMEOUT') #cmo.destroyProperty(getMBean('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName+'/Properties/oracle.jdbc.ReadTimeout'))

cmo.createProperty('oracle.jdbc.ReadTimeout') cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName+'/Properties/oracle.net.CONNECT_TIMEOUT')

cmo.setValue('10000') cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName+'/Properties/oracle.jdbc.ReadTimeout')

cmo.setValue('20000') cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCConnectionPoolParams/'+dsName)

cmo.setInactiveConnectionTimeoutSeconds(120) cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCConnectionPoolParams/'+dsName)

cmo.setConnectionReserveTimeoutSeconds(30) cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCConnectionPoolParams/'+dsName)

cmo.setStatementTimeout(120) save()

activate() print 'Timeout settings for the datasource '+dsName+' has been completed'





def main():



adminURL='t3://localhost:7001'

adminUserName='weblogic'

adminPassword='weblogic1'

connect(adminUserName, adminPassword, adminURL)

setJDBCTimeoutProperties()

disconnect() main()

Script

Before executing the script, change the configurations as required.

Execute the script — <<Oracle_Home>>\oracle_common\common\bin\wlst.cmd SetJDBCTimeoutProperties.py

Restart the server after successful execution. Now the JDBC connection timeout properties are set to the data source.

Under advanced section