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 閱讀(173) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          公告

          希望有一天

          我能用鼠標雙擊我的錢包

          然后選中一張100元

          按住“ctrl+c”

          接著不停的“ctrl+v”

          嘻嘻~~~笑醒~~~



          導航

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

          統計

          常用鏈接

          留言簿(6)

          隨筆分類(102)

          隨筆檔案(398)

          文章分類

          文章檔案(10)

          有趣網絡

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 三门县| 甘孜县| 涿鹿县| 汉阴县| 泰宁县| 安远县| 苏尼特右旗| 新泰市| 错那县| 奉贤区| 鲁山县| 建湖县| 永修县| 准格尔旗| 宜州市| 福建省| 民县| 巨鹿县| 西盟| 石渠县| 闸北区| 黄平县| 游戏| 白山市| 佛山市| 手游| 瑞昌市| 治多县| 前郭尔| 磴口县| 潮州市| 广宗县| 永丰县| 习水县| 五指山市| 沙河市| 白城市| 兰坪| 藁城市| 乡宁县| 台东县|