Loading...

java .net

从weblogic连接池得到Connection

public class Test {

    public static void main(String[] args) {
        DataSource ds = null;
        Context ctx = null;
        Connection myConn = null;
        try {
            /*
            * 获得WebLogic ServerJNDI初始上下文信息
            */
            ctx = getInitialContext();
            /*
            * 建立数据源对象
            */
            ds = (javax.sql.DataSource) ctx.lookup("datasource");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private static Context getInitialContext() throws Exception {
        String url = "t3://localhost:7001";
        String user = "";// 对应的weblogic管理名字
        String password = "";// 密码
        Properties properties = null;
        try {
            properties = new Properties();
            properties.put(Context.INITIAL_CONTEXT_FACTORY,
                    "weblogic.jndi.WLInitialContextFactory");
            properties.put(Context.PROVIDER_URL, url);
            if (user != null) {
                properties.put(Context.SECURITY_PRINCIPAL, user);
                properties.put(Context.SECURITY_CREDENTIALS,
                        password == null ? "" : password);
            }
            return new InitialContext(properties);
        } catch (Exception e) {
            throw e;
        }
    }

}

posted on 2008-08-26 22:06 阅读(163) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

公告

希望有一天

我能用鼠标双击我的钱包

然后选中一张100元

按住“ctrl+c”

接着不停的“ctrl+v”

嘻嘻~~~笑醒~~~



导航

<2008年8月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

统计

常用链接

留言簿(6)

随笔分类(102)

随笔档案(398)

文章分类

文章档案(10)

有趣网络

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜