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

📄 collegebean.java

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

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.CallableStatement;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Vector;

public class CollegeBean 
{
    
    Connection con=null;
    PreparedStatement ps=null;
    ResultSet rs=null;
    CallableStatement cs=null;
    DBConnection db=new DBConnection("CollegePool",500);
    
    
    
    //执行学院添加功能
    public String insertCollege(kjc_College c)
    {
      try
      {
        con=db.getConnection();
        cs=con.prepareCall("{call College(?,?,?,?,?)}");
        cs.setInt(1,c.getCollegeID());
        cs.setString(2,c.getCollegeName());
        cs.setString(3,c.getOfficeTel());
        cs.setString(4,c.getPrincipal());
        cs.setString(5,"add");
        cs.executeUpdate();
        return "添加成功";
      }//end block try
      catch(Exception e)
      {
        e.printStackTrace();
        return "添加失败";
      }//end block catch
    }//end method insertCollege()
    
    
    //执行的是学院的修改操作
    public String updateCollege(kjc_College c)
    {
      try
      {
        con=db.getConnection();
        cs=con.prepareCall("{call College(?,?,?,?,?)}");
        cs.setInt(1,c.getCollegeID());
        cs.setString(2,c.getCollegeName());
        cs.setString(3,c.getOfficeTel());
        int Principal=Integer.parseInt(c.getPrincipal());
        cs.setInt(4,Principal);
        cs.setString(5,"edit");
        cs.executeUpdate();
        return "修改成功";
      }//end block try
      catch(Exception e)
      {
        e.printStackTrace();
        return "修改失败";
      }//end block catch
    }//end method updateCollege()
    
    
    
    //执行的是学院的删除操作
    public String deleteCollege(kjc_College c)
    {
      try
      {
        con=db.getConnection();
        cs=con.prepareCall("{call College(?,?,?,?,?)}");
        cs.setInt(1,c.getCollegeID());
        cs.setString(2,"");
        cs.setString(3,"");
        cs.setString(4,"");
        cs.setString(5,"del");
        cs.executeUpdate();
        return "删除成功";
      }//end block try
      catch(Exception e)
      {
        e.printStackTrace();
        return "删除失败";
      }//end block catch
    }//end method deleteCollege()
    
    
    
    //查询所有的College信息
    public Collection SelectCollege()
    {
      Vector v=new Vector();
      try
      {
        con=db.getConnection();
        ps=con.prepareStatement("select * from kjc_College");
        rs=ps.executeQuery();
        while(rs.next())
        {
          kjc_College c=new kjc_College();
          c.setCollegeID(rs.getInt("CollegeID"));
          c.setCollegeName(rs.getString("CollegeName"));
          c.setOfficeTel(rs.getString("OfficeTel"));
          c.setPrincipal(rs.getString("Principal"));
          v.add(c);
        }
        rs.close();
        ps.close();
        con.close();
        return v;
      }//end block try
      catch(Exception e)
      {
        return null;
      }//end block catch
    }//end method selectcollege()
    
    
    public ResultSet getPeople(String tempName)
    {
      try
      {
        con=db.getConnection();
        ps=con.prepareStatement("select * from kjc_People where PeopleName!='"+ tempName +"'");
        rs=ps.executeQuery();
        return rs;
      }//end block try
      catch(Exception e)
      {
        e.printStackTrace();
        return null;
      }//end block catch
    }//end method getPeople
    
    
    public kjc_College getCollegeByID(int id)
    {
          try
          {
            con=db.getConnection();
            ps=con.prepareStatement("select * from kjc_College where CollegeID='"+id+"'");
            rs=ps.executeQuery();
             kjc_College kc=new kjc_College();
            while(rs.next())
            {
              kc.setCollegeID(rs.getInt("CollegeID"));
              kc.setCollegeName(rs.getString("CollegeName"));
              kc.setOfficeTel(rs.getString("OfficeTel"));
              kc.setPrincipal(rs.getString("Principal"));
            }
            return kc;
          }//end block try
          catch(Exception e)
          {
            e.printStackTrace();
            return null;
          }//end block catch
    }
    
    
    public kjc_College FindCollegeMessage(int id)
    {
         try
          {
            con=db.getConnection();
            ps=con.prepareStatement("select kjc_College.CollegeID,kjc_College.CollegeName,kjc_College.OfficeTel,kjc_People.PeopleName from kjc_College,kjc_People where kjc_College.Principal=kjc_People.PeopleID and kjc_College.CollegeID='"+id+"'");
            rs=ps.executeQuery();
            kjc_College kc=new kjc_College();
            while(rs.next())
            {
              kc.setCollegeID(rs.getInt("CollegeID"));
              kc.setCollegeName(rs.getString("CollegeName"));
              kc.setOfficeTel(rs.getString("OfficeTel"));
              kc.setPrincipal(rs.getString("PeopleName"));
            }
            return kc;
          }//end block try
          catch(Exception e)
          {
            e.printStackTrace();
            return null;
          }//end block catch
    }//end method FindCollegeMessage(id)
    
    
}//end class collegeBean

⌨️ 快捷键说明

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