⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sb_customermanagerbean.java~14~

📁 用j2ee开发的一个旅店管理系统
💻 JAVA~14~
字号:
package com.xc.hotelmanager.hotel.control.session;import javax.ejb.*;import java.util.*;import java.lang.NullPointerException;import com.xc.hotelmanager.hotel.model.*;import com.xc.hotelmanager.hotel.exception.*;import com.xc.hotelmanager.hotel.control.EjbGetter;import java.sql.*;import com.xc.hotelmanager.hotel.control.entity.*;public class SB_CustomerManagerBean implements SessionBean {  SessionContext sessionContext;  public void ejbCreate() throws CreateException {    /**@todo Complete this method*/  }  public void ejbRemove() {    /**@todo Complete this method*/  }  public void ejbActivate() {    /**@todo Complete this method*/  }  public void ejbPassivate() {    /**@todo Complete this method*/  }  public void setSessionContext(SessionContext sessionContext) {    this.sessionContext = sessionContext;  }  public Customer loadCustomer(String cid)  throws HotelManagerException {    try {      TbCustomer ejbCustomer = EjbGetter.getTbCustomerHome().findByPrimaryKey(          cid);      return ejbCustomer.getCustomer();    }    catch (Exception ex) {      throw new HotelManagerException("SB_CusMangerbean.saveCustomer Eorr:" +                                      ex.getMessage());    }  }  public Customer exitCustomer(String cid) throws HotelManagerException {    TbCustomer ejbCustomer = null;    try {      ejbCustomer = EjbGetter.getTbCustomerHome().findByPrimaryKey(cid);      return ejbCustomer.getCustomer();    }    catch (Exception ex) {      if (ejbCustomer==null) {        return null;      }      else {        throw new HotelManagerException("SB_CusMangerbean.existCustomer Eorr:" +                                        ex.getMessage());      }    }  }  public void removeCustomer(String cid) throws HotelManagerException {      try {        TbCustomer ejbCustomer = EjbGetter.getTbCustomerHome().findByPrimaryKey(            cid);        // ejbBook.setRemoveDate(new Timestamp(System.currentTimeMillis()));      }      catch (Exception ex) {        throw new HotelManagerException(ex.getMessage());      }  }  public Customer saveCustomer(Customer cus)throws HotelManagerException {      try {        TbCustomer ejbCustomer = EjbGetter.getTbCustomerHome().findByPrimaryKey(            cus.getCid());        ejbCustomer.setCustomer(cus);        return cus;      }      catch (Exception ex) {        throw new HotelManagerException("SB_CusMangerbean.saveCustomer Eorr:" +                                        ex.getMessage());      }  }  public Customer addCustomer(Customer cus)throws HotelManagerException {      try {        TbCustomer ejbCustomer = EjbGetter.getTbCustomerHome().create(cus.            getCid());        ejbCustomer.setCustomer(cus);        return cus;      }      catch (Exception ex) {        throw new HotelManagerException("SB_CusMangerbean.addCustomer Eorr:" +                                        ex.getMessage());      }    }    public Collection getAllCustomer() throws HotelManagerException {        try {          String sql = "select * from Customer";          System.out.print("SB_customerMangerBEAN.GETaLL  ok");          return this.loadBySql(sql);        }        catch (Exception ex) {          System.out.print("SB_customerMangerBEAN.GETaLL");          throw new HotelManagerException(ex.getMessage());        }      }      private Collection loadBySql(String sql) throws Exception {      Connection conn = EjbGetter.getDataSource().getConnection();      Statement st = conn.createStatement();      ResultSet rs = st.executeQuery(sql);      Collection result = new Vector();      while (rs.next()) {        Customer cus = new Customer();        cus.setCid(rs.getString("cid"));        cus.setCname(rs.getString("cname"));        cus.setCsex(rs.getString("csex"));        cus.setCnote(rs.getString("cnote"));        result.add(cus);      }      rs.close();      conn.close();      return result;    }  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -