免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3344 | 回复: 2
打印 上一主题 下一主题

[WebLogic] WebLogic9.2 + MS SQLServer2000连接池 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-10-02 23:38 |只看该作者 |倒序浏览
1。系统平台
    WIN2003+WebLogic9.2+MS SQLServer2000(已经打上SP4补丁,使用的是SP3驱动)

2。修改C:\bea\weblogic92\server\bin\startWLS.cmd中的CLASSPATH
set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%WL_HOME%\server\lib\msbase.jar;%WL_HOME%\server\lib\msutil.jar;%WL_HOME%\server\lib\mssqlserver.jar;

3。新建立的域中添加了msbase.jar,mssqlserver.jar,msutil.jar ,wlclient.jar包
        C:\bea\user_projects\domains\base_domain\lib

4。在WebLogic9.2中不管使用WebLogic9.2自带的驱动还是选用MS的驱动测试连接都能完成。


5。测试代码如下:
package com.until;

import java.sql.Connection;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class ConnDatabasePool {

        /**
         * @param args
         */
        public static void main(String[] args) {
                  Properties properties = null;
                  DataSource ds=null;
                  String user = null;
                  String password = null;
                  
                  
                  try {
                  properties = new Properties();
                  properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
                  properties.put(Context.PROVIDER_URL, "t3://localhost:7001");
                  if (user != null) {
                  properties.put(Context.SECURITY_PRINCIPAL, user);
                  properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
                  }

                  Context ctx = new InitialContext(properties);
                  ds = (javax.sql.DataSource) ctx.lookup("SQLServerJNDI");//SQLServerJNDI为WebLogic9.2 中配置的JNDI 名称
                  Connection con = ds.getConnection();
                  if(con!=null){
                        System.out.println("数据库连接成功!");
                                }
                    }catch(Exception e){
                                System.out.println("数据库连接失败!");
                                System.out.println(e.getMessage());
                            }                        
                }

        }

6。经编译下面测试程序后给出如下提示:
         数据库连接失败!
         Unexpected Exception

希望大家能够帮助解决,谢谢!!!!!!!!!!!!!!!!!!

论坛徽章:
0
2 [报告]
发表于 2007-10-03 19:27 |只看该作者
看来你的DS是找到了,但取得连接的时候失败了,把异常栈打出来看看

论坛徽章:
0
3 [报告]
发表于 2007-10-04 14:24 |只看该作者

谢谢大家的支持

谢谢大家的支持,问题已经解决了

顺便把解决方法跟大家说下

主要是由于程序的问题,将程序该动为下面的方式后就可以了
                        Properties env=new Properties();
                    env.put(InitialContext.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
                                    env.put(InitialContext.PROVIDER_URL, url);   //地址及端口号
                        env.put(InitialContext.SECURITY_PRINCIPAL, user);//登录到数据库的用名
                        env.put(InitialContext.SECURITY_CREDENTIALS, password);//密码
                        InitialContext ctx = new InitialContext(env);
                                    DataSource con= (DataSource) ctx.lookup(JDNIName);//JNDI名称为mytest
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP