如何用编程的方式得到weblogic上的所有的ConnectionPool?

outlier 2002-12-04 04:53:30
好像要用到weblogic提供的什么类,谁知道具体的怎么实现?
...全文
84 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fltwt 2002-12-05
  • 打赏
  • 举报
回复
D:\bea\weblogic700\samples\server\src\examples\jdbc\pool\dynamic
下面的几个程序,你仔细看看了。
package examples.jdbc.pool.dynamic;

import java.sql.Connection;
import java.sql.SQLException;

import java.util.Iterator;
import java.util.Set;
import java.util.Properties;

import javax.naming.Context;
import weblogic.jndi.Environment;
import weblogic.management.configuration.JDBCConnectionPoolMBean;
import weblogic.management.configuration.ServerMBean;
import weblogic.management.MBeanHome;


/**
* This class demonstrates dymamic creation, using and deletion of Connection
* Pools via Weblogic management API.
*/
public class DynamicConnectionPoolHelper {
private Context ctx = null;

private MBeanHome mbeanHome = null;
private ServerMBean serverMBean = null;

// Connection Pool
private JDBCConnectionPoolMBean myConnectionPool = null;

// DataBase attributes
private String dbUsername = "examples";
private String dbPassword = "examples";
private String dbURL = "jdbc:pointbase:server://localhost/demo";
private String dbDriverName = "com.pointbase.jdbc.jdbcUniversalDriver";

// Security credentials
private String password = null;
private String serverName = "examplesServer";
private String url = null;
private String userName = null;

/**
* Creates and starts up a Connection Pool using
* WebLogic management API.
*/
public JDBCConnectionPoolMBean createConnectionPool(String pNameOfConnectionPool) throws SQLException {
System.out.println("Creating Connection Pool...");
try {
// Get context
/*
url = "t3://localhost:7001";
userName = "weblogic";
password = "weblogic";
*/
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(userName);
env.setSecurityCredentials(password);
ctx = env.getInitialContext();

this.mbeanHome = (MBeanHome)ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
this.serverMBean = (ServerMBean)mbeanHome.getAdminMBean(serverName, "Server");

// Get a set of JDBC connection pools for this Domain.
// Test whether the connection pool exists first and if it does, delete it.
Set connectionPools = mbeanHome.getMBeansByType("JDBCConnectionPool", mbeanHome.getDomainName());

Iterator iter = connectionPools.iterator();
System.out.println("Looping through all connection pools...");
while (iter.hasNext()) {
JDBCConnectionPoolMBean aConnectionPool = (JDBCConnectionPoolMBean)iter.next();
System.out.println(aConnectionPool.getName());
if (aConnectionPool.getName().equals(pNameOfConnectionPool)) {
this.deleteConnectionPool(aConnectionPool);
break;
}
}

// Create Connection Pool
myConnectionPool = (JDBCConnectionPoolMBean)mbeanHome.createAdminMBean(
pNameOfConnectionPool, "JDBCConnectionPool", mbeanHome.getDomainName());

System.out.println("Creating Connection Pool: " + pNameOfConnectionPool);

Properties props = new Properties();
props.put("user", this.dbUsername);
props.put("password", this.dbPassword);

myConnectionPool.setURL(this.dbURL);
myConnectionPool.setDriverName(this.dbDriverName);
myConnectionPool.setProperties(props);
/*
myConnectionPool.setLoginDelaySeconds(1);
myConnectionPool.setInitialCapacity(1);
myConnectionPool.setMaxCapacity(10);
myConnectionPool.setCapacityIncrement(1);
myConnectionPool.setShrinkingEnabled(true);
myConnectionPool.setShrinkPeriodMinutes(10);
myConnectionPool.setRefreshMinutes(10);
myConnectionPool.setTestTableName("TestDynamicCreation");
myConnectionPool.setTestConnectionsOnReserve(true);
myConnectionPool.setTestConnectionsOnRelease(true);
*/

// Target the Connection Pool to the specified server.
myConnectionPool.addTarget(serverMBean);
System.out.println("Starting up connection pool.");
return myConnectionPool;
} catch (Exception e){
throw new SQLException(e.toString());
}
}

/**
* Shuts down and deletes Connection Pool from configuratrion
* using WebLogic management API.
*/
public void deleteConnectionPool(JDBCConnectionPoolMBean pConnectionPoolMBean) throws SQLException {
System.out.println("Deleting Connection Pool...");
try {
// Remove Connection Pool from the server
pConnectionPoolMBean.removeTarget(serverMBean);

// Remove Connection MBean from the configuration
mbeanHome.deleteMBean(pConnectionPoolMBean);

} catch (Exception ex) {
throw new SQLException(ex.toString());
}
}
}
outlier 2002-12-04
  • 打赏
  • 举报
回复
好像用不到:(。
fltwt 2002-12-04
  • 打赏
  • 举报
回复
Weblogic 7.0
$root:\bea\weblogic700\samples\server\src\examples\jdbc\
Weblogic 6.x
$root:\bea\wlserver6.1\samples\examples\jdbc
有几个例子,应该可以满足你的要求吧。

1,223

社区成员

发帖
与我相关
我的任务
社区描述
企业软件 中间件技术
社区管理员
  • 中间件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧