呆呆向前冲的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 阅读(709) 评论(0)  编辑  收藏 所属分类: 工作:Java技术

只有注册用户登录后才能发表评论。


网站导航: