Chinaunix首页 | 论坛 | 博客
  • 博客访问: 182055
  • 博文数量: 88
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 914
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-10 13:41
文章分类

全部博文(88)

文章存档

2010年(2)

2009年(35)

2008年(51)

我的朋友

分类: Java

2008-11-14 15:24:59

        Statement stmt = null;
        Connection conn = null;
        ResultSet res = null;
        try {
            Hashtable env = new Hashtable();
            env.put(InitialContext.INITIAL_CONTEXT_FACTORY,
                    "weblogic.jndi.WLInitialContextFactory");
            env.put(InitialContext.PROVIDER_URL, "t3://localhost:8090"); // webLogic端口IP
            env.put(InitialContext.SECURITY_PRINCIPAL, "weblogic"); // webLogic连接用户
            env.put(InitialContext.SECURITY_CREDENTIALS, "weblogic");// webLogic密码
            InitialContext ctx = new InitialContext(env);
            DataSource ds = (DataSource) ctx.lookup("openetdb2"); // JNDI名字
            conn = ds.getConnection();
            stmt = conn.createStatement();
            res = stmt.executeQuery("select * from table");
            System.out.println("id------name------address");
            while (res.next()) {
                int id = res.getInt(1);
                String name = res.getString(2).trim();
                java.sql.Date date = res.getDate(3);
                System.out.println("id="+id + ",name ="+name );
                if(date != null)
                {
                    System.out.println(date.toString());
                }
                
            }
        } catch (SQLException sse) {
            System.out.println("sql error!");
        } catch (NamingException e) {
            System.out.println("namingexception");
        }
        try {
            stmt.close();
            conn.close();
        } catch (SQLException se) {
        }
阅读(936) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~