WLST命令用于更新JDBC DataSource URL

时间:2013-08-07 13:57:07

标签: java jdbc weblogic datasource wlst

我使用Weblogic控制台导航到数据源并更新数据源中的URL。 有什么方法可以使用WLST命令做同样的事情。我需要从命令更新。

我只需要更新数据源的URL。

2 个答案:

答案 0 :(得分:3)

我们通过wlst脚本以稍微不同的方式执行此操作:

edit()

# set url and remove the target so we can redeploy without 
# restarting managed server
startEdit()

cd("/JDBCSystemResources/"+dsName)
targets = get('Targets')

# set an array ob empty objects to the datasource's targets
set('Targets',jarray.array([], ObjectName))

cd("JDBCResource/"+dsName+"/JDBCDriverParams/"+dsName)
set("Url", dbURL)

save()
activate()

# reset thge original targets so the datasource will be refreshed
startEdit()
cd("/JDBCSystemResources/"+dsName)
set('Targets', targets)

save()
activate()

我发现我需要做的事情是更改数据源对象上的URL不会将其重新部署到数据源所连接的任何托管受管服务器。如果使用托管服务器,则必须将目标设置为空,保存数据源,然后设置原始目标,再次保存。这会将数据源重新部署到任何托管服务器。

唯一的替代方法是重新启动任何托管服务器。

如果您的管理服务器也是您的托管服务器(即没有托管服务器),您无需担心上述脚本中任何与目标混乱的问题。

答案 1 :(得分:0)

是的,可以使用WLST在线命令。让我们说'myds'是您希望更改URL的示例数据源名称。您必须在编辑树中进行更改。该URL在JDBCDriverParams mbean树中可用,因此导航到该mbean,然后使用set属性setUrl命令以新值更改当前值。更改后使用save(),activate()命令。

`

     1. cd('/JDBCSystemResources/myds/JDBCResource/myds')
     2. cd('JDBCDriverParams/myds')
     3. ls()
     4. cmo.setUrl('new.db.url:port')

` 有关详细信息,您可以参考一些WLST datasource configuration脚本。