呆呆向前沖的blog

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            78 隨筆 :: 43 文章 :: 5 評論 :: 74 Trackbacks
          package com.satesoft.testjndi;

          import java.sql.
          *;
          import java.util.
          *;
          import javax.naming.
          *;
          import javax.sql.
          *;

          public class TestJNDI {
            
          public TestJNDI() {
            }


            
          public static void main(String[] args) {
              TestJNDI testJNDI1 
          = new TestJNDI();
              testJNDI1.connect();
            }


            
          public void connect() {
              Context ctx 
          = null;
              Hashtable ht 
          = new Hashtable();
              ht.put(Context.PROVIDER_URL, 
          "t3://localhost:7001");
              ht.put(Context.INITIAL_CONTEXT_FACTORY,
                     
          "weblogic.jndi.WLInitialContextFactory");
          //    ht.put(Context.SECURITY_PRINCIPAL,"wwx");
          //    ht.put(Context.SECURITY_CREDENTIALS,"11111111");
              try {
                ctx 
          = new InitialContext(ht);
                System.
          out.println("ok");
                DataSource ds 
          = (DataSource) ctx.lookup("sapp_source");
                Connection conn 
          = ds.getConnection();
                PreparedStatement pstmt 
          = conn.prepareStatement("SELECT * FROM S_ENTITY");
                ResultSet rs 
          = pstmt.executeQuery();
                
          while (rs.next()){
                  System.
          out.println(rs.getString(2));
                }

                pstmt.close();
                conn.close();
              }

              
          catch (SQLException ex) {
              }

              
          catch (NamingException e) {
                e.printStackTrace();
              }

              
          finally {
                
          try {
                  ctx.close();
                }

                
          catch (Exception e) {
                }

              }

            }

          }
          posted on 2005-08-17 23:53 呆呆向前沖的blog 閱讀(715) 評論(0)  編輯  收藏 所屬分類: 工作:Java技術
          主站蜘蛛池模板: 双辽市| 黄龙县| 乐陵市| 友谊县| 双鸭山市| 德江县| 乐至县| 九寨沟县| 仁化县| 浙江省| 建平县| 景泰县| 达孜县| 阜新市| 汉阴县| 拜泉县| 兴文县| 焉耆| 蛟河市| 德保县| 石柱| 梨树县| 绍兴市| 尉氏县| 盐边县| 华亭县| 海原县| 山西省| 阿拉善盟| 汝州市| 将乐县| 社旗县| 瑞昌市| 马鞍山市| 大余县| 镇江市| 黔西| 中江县| 德州市| 沧州市| 龙门县|