File 1: datasource.properties

dsname=testpool
server=AdminServer
testTableName=SQL SELECT 1 FROM DUAL
#testTableName=jndi=jdbc/oracle
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:ORCL
userid=xxxx
password=xxxx
maxCapacity=9

File 2: createDatasource.py

 

"""
This script configures a JDBC data source as a System Module and deploys it
to the server
"""
connect("weblogic","weblogic")
edit()
# Load config params
from java.io import FileInputStream
propInputStream = FileInputStream("datasource.properties")
configProps = Properties()
configProps.load(propInputStream)
propInputStream.close()
# Init vars
dsname=configProps.get("dsname")
server=configProps.get("server")
testTableName=configProps.get("testTableName")
jndi=configProps.get("jndi")
maxCapacity=Integer.parseInt(configProps.get("maxCapacity"))
url=configProps.get("url")
driver=configProps.get("driver")
userid=configProps.get("userid")
password=configProps.get("password")
cd("Servers/"+server)
target=cmo
cd("../..")
try:
    startEdit()
    # start creation
    print ‘Creating JDBCSystemResource with name ‘+dsname
    jdbcSR = create(dsname,"JDBCSystemResource")
    theJDBCResource = jdbcSR.getJDBCResource()
    theJDBCResource.setName(dsname)
    connectionPoolParams = theJDBCResource.getJDBCConnectionPoolParams()
    connectionPoolParams.setInactiveConnectionTimeoutSeconds(60)
    connectionPoolParams.setMaxCapacity(maxCapacity)
    connectionPoolParams.setTestTableName(testTableName)
    dsParams = theJDBCResource.getJDBCDataSourceParams()
    dsParams.addJNDIName(jndi)
    driverParams = theJDBCResource.getJDBCDriverParams()
    driverParams.setUrl(url)
    driverParams.setDriverName(driver)
    driverParams.setPassword(password)
    # driverParams.setLoginDelaySeconds(60)
    driverProperties = driverParams.getProperties()
    proper = driverProperties.createProperty("user")
    #proper.setName("user")
    proper.setValue(userid)
    jdbcSR.addTarget(target)
    save()
    activate(block="true")
    print ‘Done configuring the data source of ‘ + dsname
except:
    print ‘Failed to configuring the data source of ‘ + dsname;
    cancelEdit(‘y’);
    #undo(‘true’, ‘y’);
disconnect();
删除 DataSource:

try:
    connect(“weblogic”, “weblogic”, “t3://localhost:7001”)
    edit()
    startEdit()
    delete(‘testpool’,’JDBCSystemResource’)
    activate()
    print “Done deleting a datasource – “ + dsname
    disconnect();
except Exception:
    print “Error: Caught exception in delDataSource(). Exiting!”
    dumpStack()

转载请注明:WebLogic Android 博客 » 使用WLST创建和删除DataSource