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


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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           

          公告

          希望有一天

          我能用鼠標雙擊我的錢包

          然后選中一張100元

          按住“ctrl+c”

          接著不停的“ctrl+v”

          嘻嘻~~~笑醒~~~



          導航

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

          統計

          常用鏈接

          留言簿(6)

          隨筆分類(102)

          隨筆檔案(398)

          文章分類

          文章檔案(10)

          有趣網絡

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 永靖县| 女性| 开鲁县| 大英县| 盐池县| 隆林| 大悟县| 万源市| 全南县| 望奎县| 英吉沙县| 澎湖县| 富源县| 和静县| 天等县| 准格尔旗| 酉阳| 鄱阳县| 河北区| 平乐县| 观塘区| 中江县| 南城县| 南溪县| 呼玛县| 鄯善县| 阜城县| 河北省| 兴文县| 绥化市| 独山县| 泰和县| 正安县| 松溪县| 惠水县| 平顺县| 云和县| 安顺市| 金昌市| 海城市| 白玉县|