📄 userbo.java
字号:
//这个类将处理用户我添加和删除、修改等等的操作;
package cn.rludrea.model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
public class UserBO {
//定义一些变量[];
private ResultSet rs=null;
private Connection ct=null;
private PreparedStatement ps=null;
/**
* 返回总共有多少页;
* @author rludrea
* @param pageSize
* @return int :返回一个总共有多少页;
*/
public int getStuCount(int pageSize)
{
int pageCount=0;
int rowCount=0;
try{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select count(*) from student");
rs=ps.executeQuery();
if(rs.next())
{
rowCount=rs.getInt(1);
}
if(rowCount%pageSize==0)
{
pageCount=rowCount/pageSize;
}
else
{
pageCount=rowCount/pageSize+1;
}
}catch(Exception e)
{
e.printStackTrace();
}finally
{
new close().Close();
}
return pageCount;
}
/**
* 分页显示选课的简单内容;
* @author rludrea
* @param pageSize (int)
* @param pageNow (int)
* @return ArrayList 返回一个数组集;
*/
public ArrayList getStuByPage(int pageSize,int pageNow)
{
ArrayList al=new ArrayList();
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select top "+pageSize+" * from student where stuId not in(select top "+(pageNow-1)*pageSize+" stuId from student)");
rs=ps.executeQuery();
while(rs.next())
{
studentBean sb=new studentBean();
sb.setStuId(rs.getLong(1));
sb.setStuName(rs.getString(2));
sb.setStuPwd(rs.getString(3));
sb.setStuCourse(rs.getString(4));
al.add(sb);
}
}catch(Exception e)
{
e.printStackTrace();
}finally
{
new close().Close();
}
return al;
}
/**
* 返回总共有多少页;
* @author rludrea
* @param pageSize
* @return int :返回一个总共有多少页;
*/
public int getTeaCount(int pageSize)
{
int pageCount=0;
int rowCount=0;
try{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select count(*) from teacher");
rs=ps.executeQuery();
if(rs.next())
{
rowCount=rs.getInt(1);
}
if(rowCount%pageSize==0)
{
pageCount=rowCount/pageSize;
}
else
{
pageCount=rowCount/pageSize+1;
}
}catch(Exception e)
{
e.printStackTrace();
}finally
{
new close().Close();
}
return pageCount;
}
/**
* 分页显示选课的简单内容;
* @author rludrea
* @param pageSize (int)
* @param pageNow (int)
* @return ArrayList 返回一个数组集;
*/
public ArrayList getTeaByPage(int pageSize,int pageNow)
{
ArrayList al=new ArrayList();
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select top "+pageSize+" * from teacher where teaId not in(select top "+(pageNow-1)*pageSize+" teaId from teacher)");
rs=ps.executeQuery();
while(rs.next())
{
teacherBean tb=new teacherBean();
tb.setTeaId(rs.getInt(1));
tb.setTeaName(rs.getString(2));
tb.setTeaPwd(rs.getString(3));
tb.setCourseId(rs.getString(4));
al.add(tb);
}
}catch(Exception e)
{
e.printStackTrace();
}finally
{
new close().Close();
}
return al;
}
/**
* 这是一个管理员删除学生用户的方法;
* @author rludrea
* @param stuId (String)
* @return boolean 返回一个boolean值。
*/
public boolean delByStuId(String stuId)
{
boolean b=false ;
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("delete from student where stuId=?");
ps.setString(1, stuId);
int index=ps.executeUpdate();
if(index==1)
{
b=true;
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
new close().Close();
}
return b;
}
/**
* 这是一个管理员删除指导都是用户的方法;
* @author rludrea
* @param teaId (String)
* @return boolean 返回一个boolean值。
*/
public boolean delByTeaId(String teaId)
{
boolean b=false ;
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("delete from teacher where teaId=?");
ps.setString(1, teaId);
int index=ps.executeUpdate();
if(index==1)
{
b=true;
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
new close().Close();
}
return b;
}
/**
* 这个方法是管理员用来添加新的学生用户的;
* @author rldurea
* @param stuName (String)
* @param stuPwd (String)
* @return boolean 返回一个布尔值用来判断是否添加成功;
*/
public boolean addStu(String stuName,String stuPwd,String courseId)
{
boolean b=false;
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("insert into student values('"+stuName+"','"+stuPwd+"','"+courseId+"')");
//ps.setString(1, stuName);
//ps.setString(2, stuPwd);
int index=ps.executeUpdate();
if(index==1)
{
b=true;
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
new close().Close();
}
return b;
}
/**
* 这个方法是管理员用来修改学生信息的;
* @author rludrea
* @param stuName (String )
* @param stuPwd (String)
* @param courseId (String)
* @param stuId (String)
* @return boolean 返回一个boolean来判断是否修改成功;
*/
public boolean updateStu(String stuName,String stuPwd,String courseId,String stuId)
{
boolean b=false;
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("update student set stuName='"+stuName+"',stuPwd='"+stuPwd+"',courseId='"+courseId+"' where stuId='"+stuId+"'");
int index=ps.executeUpdate();
if(index==1)
{
b=true;
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
new close().Close();
}
return b;
}
/**
* 这个方法是管理员用来添加新的指导老师;
* @author rldurea
* @param teaName (String)
* @param teaPwd (String)
* @param courseId (String)
* @return boolean 返回一个布尔值用来判断是否添加成功;
*/
public boolean addTea(String teaName,String teaPwd,String courseId)
{
boolean b=false;
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("insert into teacher values('"+teaName+"','"+teaPwd+"','"+courseId+"')");
//ps.setString(1, stuName);
//ps.setString(2, stuPwd);
int index=ps.executeUpdate();
if(index==1)
{
b=true;
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
new close().Close();
}
return b;
}
/**
* 这个方法是管理员用来修改指导老师信息的;
* @author rludrea
* @param teaName (String )
* @param teaPwd (String)
* @param courseId (String)
* @param teaId (String)
* @return boolean 返回一个boolean来判断是否修改成功;
*/
public boolean updateTea(String teaName,String teaPwd,String courseId,String teaId)
{
boolean b=false;
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("update teacher set teaName='"+teaName+"',teaPwd='"+teaPwd+"',courseId='"+courseId+"' where teaId='"+teaId+"'");
int index=ps.executeUpdate();
if(index==1)
{
b=true;
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
new close().Close();
}
return b;
}
public studentBean getStuBean(String stuId)
{
studentBean sb=new studentBean();
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select top 1 * from student where stuId=?");
ps.setString(1, stuId);
rs=ps.executeQuery();
if(rs.next())
{
sb.setStuId(rs.getLong(1));
sb.setStuName(rs.getString(2));
sb.setStuPwd(rs.getString(3));
sb.setStuCourse(rs.getString(4));
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
new close().Close();
}
return sb;
}
public teacherBean getTeaBean(String teaId)
{
teacherBean tb=new teacherBean();
try
{
ct=new ConnDB().getConn();
ps=ct.prepareStatement("select top 1 * from teacher where teaId=?");
ps.setString(1,teaId);
rs=ps.executeQuery();
if(rs.next())
{
tb.setTeaId(rs.getInt(1));
tb.setTeaName(rs.getString(2));
tb.setTeaPwd(rs.getString(3));
tb.setCourseId(rs.getString(4));
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
new close().Close();
}
return tb;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -