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)

          有趣網絡

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 班戈县| 麻栗坡县| 徐州市| 北碚区| 通化县| 乡城县| 且末县| 咸阳市| 肃北| 宁城县| 英吉沙县| 西乡县| 吉安县| 华阴市| 内江市| 乐平市| 博野县| 招远市| 莆田市| 东城区| 宁乡县| 靖远县| 泰安市| 筠连县| 灵台县| 洛阳市| 随州市| 永善县| 碌曲县| 延庆县| 嵊州市| 泌阳县| 鱼台县| 射洪县| 栖霞市| 鸡西市| 庆城县| 百色市| 安化县| 东台市| 呈贡县|