Thursday, December 21, 2017

How to Update Datasource Connect String ?

Scenario 1) Updating all datasource with same connect string 

===============================================

step a) create updateds.py file at $DOMAIN_HOME

dsURL="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)))"
print("*** Wait for a moment trying to connect *****")
connect('weblogic','xxxxxxx','t3://localhost:7001')
print("*** Connected *****")
cd('Servers/AdminServer')
edit()
startEdit()
cd('JDBCSystemResources')
for tmpDS in allDS:
  dataSourceName=tmpDS.getName();
  print  'changing datasource connect string for', dataSourceName
  cd('/JDBCSystemResources/' + dataSourceName + '/JDBCResource/' + dataSourceName + '/JDBCDriverParams/' + dataSourceName)
  cmo.setUrl(dsURL)
  print("*** connect string changed for your: ", dataSourceName)
  print ('')
  print ('')
save()
activate()


step b) Execute updateds.py script using below commands

cd $DOMAIN_HOME/bin
. ./setDomainEnv.sh
java weblogic.WLST updateds.py

Scenario 2) Updating Single datasource(ex: SOADS) with specified connect string(ex: dsURL)

=========================================================

step a) create updateds.py file at $DOMAIN_HOME

dsURL="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)))"
print("*** Trying to Connect.... *****")
connect('weblogic','xxxxxxx','t3://localhost:7001')
print("*** Connected *****")
cd('Servers/AdminServer')
edit()
startEdit()
dsName="SOADS"
cd('JDBCSystemResources')
print  'changing datasource connect string for', dsName
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName)
cmo.setUrl(dsURL)
print("*** connect string changed for your: ", dsName)
print ('')
print ('')
save()
activate()

Step b) Execute updateds.py script using below commands

cd $DOMAIN_HOME/bin
. ./setDomainEnv.sh
java weblogic.WLST updateds.py