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

📄 rolebean.java

📁 教师办公管理系统
💻 JAVA
字号:
package to.model.Role;

import java.sql.Connection;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Collection;
import java.util.Vector;
import to.model.DBConnection;
import to.model.Right.RightItem;
import java.sql.PreparedStatement;

public class RoleBean 
{
  
  Connection con=null;
  CallableStatement cs=null;
  ResultSet rs=null;
  PreparedStatement ps=null;
  DBConnection db=new DBConnection("RolePool",500);
  
  
  
  //Role insert
  public String insertRole(RoleItem ri)
  {
    try
    {
      con=db.getConnection();
      cs=con.prepareCall("{call kjcRole(?,?,?,?)}");
      cs.setInt(1,ri.getRoleID());
      cs.setString(2,ri.getRoleName());
      cs.setInt(3,ri.getRightID());
      cs.setString(4,"add");
      cs.executeUpdate();
      return "添加成功";
    }//end block try
    catch(Exception e)
    {
      e.printStackTrace();
      return "添加失败";
    }//end block catch
  }//end method insertRole()
  
  
  
  //kjc_Role update
  public String updateRole(RoleItem ri)
  {
    try
    {
      con=db.getConnection();
      cs=con.prepareCall("{call kjcRole(?,?,?,?)}");
      cs.setInt(1,ri.getRoleID());
      cs.setString(2,ri.getRoleName());
      cs.setInt(3,ri.getRightID());
      cs.setString(4,"edit");
      cs.executeUpdate();
      return "修改成功";
    }//end block try
    catch(Exception e)
    {
      e.printStackTrace();
      return "修改失败";
    }//end block catch
  }//end method updateRole
  
  
  //kjc_Role delete
  public String deleteRole(RoleItem ri)
  {
    try
    {
      con=db.getConnection();
      cs=con.prepareCall("{call kjcRole(?,?,?,?)}");
      cs.setInt(1,ri.getRoleID());
      cs.setString(2,ri.getRoleName());
      cs.setInt(3,ri.getRightID());
      cs.setString(4,"del");
      cs.executeUpdate();
      return "删除成功";
    }//end block try
    catch(Exception e)
    {
      e.printStackTrace();
      return "删除失败";
    }//end block catch
  }//end method deleteRole
  
  
//kjc_Role SelectAll
  public Collection selectAllRole()
  {
    try
    {
      Vector v=new Vector();
      con=db.getConnection();
      cs=con.prepareCall("{call kjcRole(?,?,?,?)}");
      cs.setInt(1,0);
      cs.setString(2,"");
      cs.setInt(3,0);
      cs.setString(4,"find");
      rs=cs.executeQuery();
      while(rs.next())
      {
        RoleItem ri=new RoleItem();
        ri.setRoleID(rs.getInt("RoleID"));
        ri.setRoleName(rs.getString("RoleName"));
        ri.setRightName(rs.getString("RightName"));
        v.add(ri);
      }//end block while
      return v;
    }//end block try
    catch(Exception e)
    {
      e.printStackTrace();
      return null;
    }//end block catch
  }//end method selectAllRole
  
  
  //kjc_Role getRolebyID
  public RoleItem getRolebyID(int id)
  {
    try
    {
      con=db.getConnection();
      ps=con.prepareStatement("select kjc_Role.RoleID,kjc_Role.RoleName,kjc_Right.RightName,kjc_Role.RightID from kjc_Role inner join kjc_Right on kjc_Role.RightID=kjc_Right.RightID and kjc_Role.RoleID='"+id+"'");
      rs=ps.executeQuery();
      RoleItem ri=new RoleItem();
      while(rs.next())
      {
        ri.setRoleID(rs.getInt("RoleID"));
        ri.setRoleName(rs.getString("RoleName"));
        ri.setRightName(rs.getString("RightName"));
        ri.setRightID(rs.getInt("RightID"));
      }//end block while
      return ri;
    }//end block try
    catch(Exception e)
    {
      e.printStackTrace();
      return null;
    }//end block catch
  }//end method getRolebyID
  
  
  //kjc_RightName
  public Collection getRightName()
  {
    try
    {
      Vector v=new Vector();
      con=db.getConnection();
      ps=con.prepareStatement("select RightID,RightName from kjc_Right");
      rs=ps.executeQuery();
      while(rs.next())
      {
        RightItem ri=new RightItem();
        ri.setRightID(rs.getInt("RightID"));
        ri.setRightName(rs.getString("RightName"));
        v.add(ri);
      }//end block while
      return v;
    }//end block try
    catch(Exception e)
    {
      e.printStackTrace();
      return null;
    }//end block catch
  }//end method getRightName()
  
}//end class RoleBean

⌨️ 快捷键说明

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