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

📄 usersessionbean.java

📁 一个使用EJB开发的真实项目
💻 JAVA
字号:
package ejb;

import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
import javax.naming.*;
import java.util.*;

/**
 * 操作UserInfo表
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class UserSessionBean implements SessionBean {
    SessionContext sessionContext;
    public void ejbCreate() throws CreateException {
    }

    public void ejbRemove() {
    }

    public void ejbActivate() {
    }

    public void ejbPassivate() {
    }

    public void setSessionContext(SessionContext sessionContext) {
        this.sessionContext = sessionContext;
    }
    /**
     * 检测用户名
     * @param us String
     * @param pw String
     * @return boolean
     */
    public boolean  check(String us, String pw) {
        boolean bool=false;
        try{
            Context ct = new InitialContext();
            UserInfoHome home=(UserInfoHome)ct.lookup("UserInfo");
            UserInfo rm = home.findByPrimaryKey(us);
            if(rm.getUserCode().equals(us)&&rm.getUserPW().equals(pw))bool=true;
        }catch(Exception e){e.printStackTrace();}
        return bool;
  }
  /**
   * 注册用户信息
   * @param us String
   * @param name String
   * @param pw String
   * @param shenfenzheng String
   * @param telephone String
   * @param address String
   * @param youzhengbianma String
   * @param email String
   * @return boolean
   */
  public boolean  inster(String us, String name,String pw,String shenfenzheng,String telephone,
                         String address,String youzhengbianma,String email) {
    boolean bool=false;
    try{
        Context ct = new InitialContext();
        UserInfoHome home=(UserInfoHome)ct.lookup("UserInfo");
        UserInfo rm = home.create(us);
        rm.setUserName(name);
        rm.setUserPW(pw);
        rm.setShenfenzheng(shenfenzheng);
        rm.setTelephone(telephone);
        rm.setAddress(address);
        rm.setYouZhengBianMa(youzhengbianma);
        rm.setEmail(email);
        bool=true;
    }catch(Exception e){e.printStackTrace();}
    return bool;
  }
  /**
   * 删除
   * @param us String
   * @return boolean
   */
  public boolean  delete(String us){
      boolean bool=false;
      try{
          Context ct = new InitialContext();
        UserInfoHome home=(UserInfoHome)ct.lookup("UserInfo");
        UserInfo rm = home.findByPrimaryKey(us);
        rm.remove();
        bool=true;
      }catch(Exception e){e.printStackTrace();}
      return bool;
  }
  /**
   * 修改
   * @param us String
   * @param name String
   * @param pw String
   * @param shenfenzheng String
   * @param telephone String
   * @param address String
   * @param youzhengbianma String
   * @param email String
   * @return boolean
   */
  public boolean xiugai(String us, String name,String pw,String shenfenzheng,String telephone,
                        String address,String youzhengbianma,String email){
      boolean bool=false;
      try{
          Context ct = new InitialContext();
          UserInfoHome home=(UserInfoHome)ct.lookup("UserInfo");
          UserInfo rm = home.findByPrimaryKey(us);
          rm.setUserName(name);
          rm.setUserPW(pw);
          rm.setShenfenzheng(shenfenzheng);
          rm.setTelephone(telephone);
          rm.setAddress(address);
          rm.setYouZhengBianMa(youzhengbianma);
          rm.setEmail(email);
          bool=true;
     }catch(Exception e){e.printStackTrace();}
      return bool;
  }
  public boolean jiance(String us){
      boolean bool=false;
      try{
          Context ct = new InitialContext();
          UserInfoHome home = (UserInfoHome) ct.lookup("UserInfo");
          UserInfo rm = home.findByPrimaryKey(us);
      }catch(Exception e){bool=true;e.printStackTrace();}
      return bool;
  }

    public List  selectAllUser() {
        ArrayList list=new ArrayList();
      try{
          Context ct = new InitialContext();
          UserInfoHome home = (UserInfoHome) ct.lookup("UserInfo");
          Iterator it=home.findAllUser().iterator();
          while(it.hasNext()){
              UserInfo userInfo=(UserInfo)it.next();
              UserInfoVo vo = new UserInfoVo();
              vo.setAddress(userInfo.getAddress());
              vo.setEmail(userInfo.getEmail());
              vo.setShenfenzheng(userInfo.getShenfenzheng());
              vo.setTelephone(userInfo.getTelephone());
              vo.setUserCode(userInfo.getUserCode());
              vo.setUserName(userInfo.getUserName());
              vo.setUserPW(userInfo.getUserPW());
              vo.setYouZhengBianMa(userInfo.getYouZhengBianMa());
              list.add(vo);
          }
      }catch(java.lang.Exception e){e.printStackTrace();}
       return list;
    }

    public List selectOnlyUser(String userCode) {

        ArrayList list=new ArrayList();
        try{
            Context ct = new InitialContext();
          UserInfoHome home = (UserInfoHome) ct.lookup("UserInfo");
          Iterator it =home.findAllOnlyUser(userCode).iterator();
          while(it.hasNext()){
              UserInfoVo vo = new UserInfoVo();
              UserInfo userInfo=(UserInfo)it.next();
              vo.setAddress(userInfo.getAddress());
              vo.setEmail(userInfo.getEmail());
              vo.setShenfenzheng(userInfo.getShenfenzheng());
              vo.setTelephone(userInfo.getTelephone());
              vo.setUserCode(userInfo.getUserCode());
              vo.setUserName(userInfo.getUserName());
              vo.setUserPW(userInfo.getUserPW());
              vo.setYouZhengBianMa(userInfo.getYouZhengBianMa());
          list.add(vo);}
        }catch(java.lang.Exception e){e.printStackTrace();}
        return list;
    }
}

⌨️ 快捷键说明

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