欢迎光临
我们一直在努力

用Java实现可保存状态的数据库生成XML树(7)-JSP教程,Java与XML

建站超值云服务器,限时71元/月

6.3.源码
6.3.1.resultedit sessionbean源码和相关文件
1.远程接口文件,resultedit.java
package com.sitechasia.ejb;

import java.rmi.*;
import javax.ejb.*;
import java.io.*;

import javax.sql.rowset;
import java.sql.sqlexception;

public interface resultedit extends ejbobject {
    
    public rowset getrowset() throws remoteexception , sqlexception ;
        
        public rowset setrowset(string sqlexp) throws remoteexception , sqlexception ;
}

2.home接口文件 resultedithome.java
package com.sitechasia.ejb;

import java.rmi.*;
import javax.ejb.*;
import java.io.*;

import java.util.hashmap;

public interface resultedithome extends ejbhome {
  public resultedit create() throws remoteexception, createexception;
  public resultedit create(hashmap startingcart) throws remoteexception, createexception;
  
}

3.bean类 resulteditbean.java
package com.sitechasia.ejb;

import java.rmi.*;
import javax.ejb.*;
import java.io.*;

import java.sql.*;
import javax.sql.*;
import sun.jdbc.rowset.*;

import javax.sql.datasource;

import javax.naming.context;
import javax.naming.initialcontext;
import javax.naming.namingexception;

import java.util.hashmap;

public class resulteditbean implements sessionbean {
    private sessioncontext sessioncontext;
    public int id;
    public string name;
        private cachedrowset crset=null;
        
        private hashmap cart;
      
        private context ctx = null;
        private datasource ds = null;
        
        public resulteditbean() {
            cart = new hashmap();
        }
        
        public void ejbcreate() {
            try {
                cart = new hashmap();
                ctx = new initialcontext();
                        ds = (datasource)ctx.lookup("java:comp/env/imis");
                }
                catch (exception e) {
                    system.out.println("ejbcreate failed:"+e.getmessage());
                    e.printstacktrace();
                }
        }
        
        public void ejbcreate(hashmap starting) {
            try {
                cart = (hashmap) starting.clone();
                ctx = new initialcontext();
                        ds = (datasource)ctx.lookup("java:comp/env/imis");
                }
                catch (exception e) {
                    system.out.println("ejbcreate failed:"+e.getmessage());
                    e.printstacktrace();
                }
        }
        
        public void ejbremove() throws remoteexception {
        }
        public void ejbactivate() throws remoteexception {
        }
        public void ejbpassivate() throws remoteexception {
        }
        public void setsessioncontext(sessioncontext sessioncontext) throws remoteexception {
            this.sessioncontext = sessioncontext;
        }
        public rowset getrowset() throws sqlexception {
            return crset;
        }
        public rowset setrowset(string sqlexp) throws sqlexception {
            connection con = null;
            try {
                con = ds.getconnection();
                statement stmt = con.createstatement();
                resultset rs =  stmt.executequery(sqlexp);
                cachedrowset t_crset = new cachedrowset();
                t_crset.populate(rs);
                rs.close();
                stmt.close();
                crset = t_crset;
                return t_crset;
            }
            finally {
                if (con != null) con.close();
            }
        }
}
 

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用Java实现可保存状态的数据库生成XML树(7)-JSP教程,Java与XML
分享到: 更多 (0)

相关推荐

  • 暂无文章