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();
                      /*
                      * 建立數(shù)據(jù)源對(duì)象
                      */
                      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 = "";// 對(duì)應(yīng)的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 閱讀(174) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          公告

          希望有一天

          我能用鼠標(biāo)雙擊我的錢(qián)包

          然后選中一張100元

          按住“ctrl+c”

          接著不停的“ctrl+v”

          嘻嘻~~~笑醒~~~



          導(dǎo)航

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

          統(tǒng)計(jì)

          常用鏈接

          留言簿(6)

          隨筆分類(lèi)(102)

          隨筆檔案(398)

          文章分類(lèi)

          文章檔案(10)

          有趣網(wǎng)絡(luò)

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 蚌埠市| 阜新| 兴宁市| 景德镇市| 屏南县| 泸州市| 富宁县| 云浮市| 毕节市| 南投市| 防城港市| 岚皋县| 沈丘县| 和林格尔县| 日土县| 平利县| 大英县| 白朗县| 翁源县| 水富县| 两当县| 盐津县| 苍山县| 修武县| 武宁县| 明水县| 武定县| 保德县| 浠水县| 宁城县| 龙山县| 高邮市| 廉江市| 红桥区| 陆良县| 津南区| 巴彦县| 临武县| 水富县| 盐源县| 万山特区|