高分求救:如何通过应用程序配置weblogic8.1的数据连接池,和连接池。(在线等待)

dby_ 2003-11-24 03:32:33
一般来说我们在配置的时候都是在IE地址栏输入http://127.0.0.1:7001/console进入控制台。如果然后点击jdbc,点击连接池,输入连接池信息,如连接池名字等等,配完之后在点击datasource,配置数据源。
以上的操作我不想在控制台里进行。我想编写一个java应用程序实现,来方便用户。请各位大侠指点。
...全文
48 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
louisqiang 2004-01-03
  • 打赏
  • 举报
回复
该问题我们也折磨了好久:后来才发现解决办法:使用weblogic提供的管理类,可以完成console完成的任何功能,下面提供一端代码:[注意:连接池的配置在7.1后与web与EJB的配置完全不一样,包括加载服务的事件监听]
//动态产生连接池的类
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;



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 = "louis";
private String dbPassword = "louis";
private String dbURL = "jdbc:weblogic:mssqlserver4";
private String dbDriverName = "weblogic.jdbc.mssqlserver4.Driver";

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

//产生一个连接池
public JDBCConnectionPoolMBean createConnectionPool(String pNameOfConnectionPool) throws SQLException
{
System.out.println("Creating Connection Pool...");
try
{
// Get context
url = "t3://127.0.0.1:7001";
userName = "louis";
password = "louisyyy";
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);
props.put("server", "127.0.0.1:1034");

myConnectionPool.setURL(this.dbURL);
myConnectionPool.setDriverName(this.dbDriverName);
myConnectionPool.setProperties(props);

// 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());
}
}
//删除一个连接池
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());
}
}
}
Tomcat4 2003-12-31
  • 打赏
  • 举报
回复
up
wangguot 2003-12-04
  • 打赏
  • 举报
回复
那个url是数据库的驱动路径
dby_ 2003-12-01
  • 打赏
  • 举报
回复
to:johncdc:
聊天室里的那个问题就是我问的。我已经访问过那个网址了。没什么帮助。
to:timpeng:
那样做是不可以的,第一缺少灵活性。而且那个超链参数及其复杂。
timpeng 2003-11-28
  • 打赏
  • 举报
回复
用控制台先成你的连接池参数,再把它更新到你要的config.xml
johncdc 2003-11-28
  • 打赏
  • 举报
回复
你看基于BEA WebLogic Server的Web应用开发”聊天实录中这么一段话,希望对你有帮助。
"
一般配置数据库连接池都是在控制台进行的。但是为了方便客户,我要编写一个java应用程序实现控制台配置数据连接池功能,请问如何实现,weblogic SDK中是否有相应的类方法?
通过JMX可以实现http://dev2dev.bea.com/code/index.jsp"
dby_ 2003-11-27
  • 打赏
  • 举报
回复
怎么没人关注我的问题,是个位大侠解决不了还是,不屑一顾。我的问题如果解决,我还有3000多可用分,我愿意清囊相送。
dby_ 2003-11-25
  • 打赏
  • 举报
回复
to johncdc
问题就是出在这里,当你的连接池连接不同的数据库时,这个密码是不同的,我就想知道这个密码是怎么生成的。我看了一下控制台的源代码程序,当你在控制台配好一个连接池,点击发布的时候是调了一个类。我不知道这个类在weblogic8中的什么位置。还有这个类有个接口参数,是一个url,这个url比较难懂,不知道什么意思。我可不可以在我得应用程序中调用这个类。具体该怎么办
to naxin:你说的j2ee中角色定义,是什么意思。我如何找到weblogic8是怎么定义的。
naxin 2003-11-24
  • 打赏
  • 举报
回复
j2ee中角色定义.
johncdc 2003-11-24
  • 打赏
  • 举报
回复
是这样的。但是估计有点困难,就是你能完全理解config.xml中所有的标签的含义,还有如密码他是加密过的,你能解密吗?
icewolf_li 2003-11-24
  • 打赏
  • 举报
回复
控制台所有的操作都是针对config.xml。你只要直接改这个config.xml就可以达到和控制台一样的效果。

1,220

社区成员

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

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