← All posts

Creating a JDBC Data Source using WLST

Full script: connection pool, JNDI name, and server targeting

Unni Pillai
Unni Pillai

Hiya,

Last night I was trying to create a JDBC Data Source using WLST for one of my colleagues.
After a lot of hit-n-trial I was able to do it, so thought I would share it here.
May come handing sometime while writing scripts to automate domain creations. ;)

-

Written by Unni on Fri 20 Feb 15:13 (IST) download

  1. # This python program would create a DataSource named ‘DS1’ and targets it to (AdminServer and MS).

  2. # Please change the code as per your environment and needs:

  3. # Change the username and password with admin username and password.

  4. #please change the localhost:7001 with he ip address:portnumber

  5. print(‘Starting…’)

  6. connect(‘weblogic’,‘weblogic’,‘t3://localhost:7001’)

  7. print(‘Starting a edit session’)

  8. edit()

  9. startEdit()

  10. # Create a new Mbean ( a JDBC resource)

  11. cd(’/’)

  12. cmo.createJDBCSystemResource(‘DS1’)

  13. #Naming the datasource

  14. cd(‘/JDBCSystemResources/DS1/JDBCResource/DS1’)

  15. cmo.setName(‘DS1’)

  16. #Setting JNDI name

  17. cd(‘/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDataSourceParams/DS1’)

  18. set(‘JNDINames’,jarray.array([String(‘DS1’)], String))

  19. cd(‘/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDriverParams/DS1’)

  20. cmo.setUrl(‘jdbc:pointbase:server://localhost:9092/demo’)

  21. cmo.setDriverName(‘com.pointbase.xa.xaDataSource’)

  22. cmo.setPassword(‘PBPUBLIC’)

  23. #Set Connection Pool specific parameters

  24. # refer: e-docs.bea.com/wls/docs92/wlsmbeanref/mbeans/JDBCConnectionPoolParamsBean.html

  25. cd(‘/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCConnectionPoolParams/DS1’)

  26. cmo.setTestConnectionsOnReserve(true)

  27. cmo.setTestTableName(‘SYSTABLES’)

  28. cmo.setConnectionReserveTimeoutSeconds(25)

  29. cmo.setMaxCapacity(20)

  30. cmo.setConnectionReserveTimeoutSeconds(10)

  31. cmo.setTestFrequencySeconds(360)

  32. # Setting the user name

  33. cd(‘/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDriverParams/DS1/Properties/DS1’)

  34. cmo.createProperty(‘user’)

  35. cd(‘/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDriverParams/DS1/Properties/DS1/Properties/user’)

  36. cmo.setValue(‘PBPUBLIC’)

  37. # Setting the database name

  38. cd(‘/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDriverParams/DS1/Properties/DS1’)

  39. cmo.createProperty(‘databaseName’)

  40. cd(‘/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDriverParams/DS1/Properties/DS1/Properties/databaseName’)

  41. cmo.setValue(‘jdbc:pointbase:server://localhost:9092/demo’)

  42. # Transaction

  43. cd(‘/JDBCSystemResources/DS1/JDBCResource/DS1/JDBCDataSourceParams/DS1’)

  44. cmo.setGlobalTransactionsProtocol(‘TwoPhaseCommit’)

  45. cd(‘/JDBCSystemResources/DS1’)

  46. # targets the DS1 to Servers(AdminServer,MS)

  47. set(‘Targets’,jarray.array([ObjectName(‘com.bea:Name=AdminServer,Type=Server’), ObjectName(‘com.bea:Name=MS,Type=Server’)], ObjectName))

  48. activate()

  49. print(‘Exiting…’)

  50. exit()

  51. # Code written by:

  52. # Unnikrishnan Pillai,

  53. # Engineer,

  54. # Oracle Global Support

-
MultiDataSources coming soon…

Now have 2 get back to work ;)

Unni

unni@unnikrishnanpillai.tk