学⽣增删改查jsp完整源码学⽣增删改查
control
1、AddStudentServlet.java
doGet
StudentDao studentDao =new StudentDaoImpl();
//1.接受表单提交信息
String Parameter("name");
int sno=Integer.Parameter("sno"));
String Parameter("sclass");
String Parameter("dpSno");
//操作类型(添加/删除)
幻灯片结束页
String Parameter("type");
//2.创建学⽣对象
Student stu=new Student();
if("add".equals(type)){
//将表单信息赋值给学⽣对象
stu.setsName(name);
stu.setSno(sno);
stu.setDpSno(dpSno);
stu.setSclass(sclass);
// 向Student表插⼊⼀个⽤户信息
boolean b=studentDao.insert(stu);
if(b){
request.setAttribute("message","插⼊成功!");
}else{
request.setAttribute("message","插⼊失败!");
}
}else{
stu.setsName(name);
stu.setSno(sno);
stu.setDpSno(dpSno);
stu.setSclass(sclass);
studentDao.update(stu);
}
ArrayList<Student> list=new ArrayList<Student>();
list=studentDao.findAllStudent();
request.setAttribute("list", list);
}
2、DeleteStudentServlet.java
doPost
int sno=Integer.Parameter("sno"));
// 删除⼀个学⽣
StudentDao studentDao =new StudentDaoImpl();
boolean b=studentDao.deleteStudentBySno(sno);
if(b){
request.setAttribute("message","删除成功!");
}else{
request.setAttribute("message","删除失败!");
}
ArrayList<Student> list=new ArrayList<Student>();
list=studentDao.findAllStudent();
request.setAttribute("list", list);
3、exitServlet.java
doGet
HttpSession Session();
Attribute("s")!=null){
}
4、LoginFilter.java
doFilter
//转换request和response对象
HttpServletRequest req=(HttpServletRequest) request;
HttpServletResponse res=(HttpServletResponse) response;
/
/创建session对象
HttpSession Session();
//获取学⽣信息
Student s=(Attribute("s");
//判断学⽣是否登录
if(s==null){//没有登录
}else{//放⾏
chain.doFilter(request, response);
}
5、LoginServlet.java
doGet
margin一个值代表什么
//1、获取表单信息
int sno=Integer.Parameter("sno"));
//2、创建数据库访问层接⼝对象
StudentDao dao=new StudentDaoImpl();
//3、根据学号查询学⽣
Student s=dao.findStudentBySno(sno);
if(s!=null){//学⽣存在
//4、创建session对象
HttpSession Session();
//5、将学⽣放⼊到session对象
session.setAttribute("s",s);
//请求并转发
//存储错误
request.setAttribute("errorMessage","该学⽣不存在!");
//请求并转发登录页⾯
}
6、SelectStudentServlet.java
doGet
StudentDao studentDao =new StudentDaoImpl();
ArrayList<Student> list=new ArrayList<Student>();
list=studentDao.findAllStudent();
request.setAttribute("list", list);
7、UpdateStudentServlet.java
doPost
StudentDao studentDao =new StudentDaoImpl();
int sno=Integer.Parameter("sno"));
Student stu=studentDao.findStudentBySno(sno);
request.setAttribute("stu", stu);
sql中update什么意思
1、StudentDao.java
/**
* 数据库接⼝
* @author Administrator
*
*/
数据库课程设计图书管理系统模板public interface StudentDao {
/**
* 插⼊⼀个学⽣
* @param student
* @return
*/
public boolean insert(Student student);
/**
* 查询所有学⽣数据
* @return 学⽣集合
*/
public ArrayList<Student>findAllStudent();
/**
* 根据学号获取学⽣信息
* @param sno 学号
* @return 查询学⽣对象
*/
public Student findStudentBySno(int sno);
/**
* 根据学号删除学⽣
* @param sno 学号
* @return true/false
*/
public boolean deleteStudentBySno(int sno);
/**
* 更新⼀个学⽣信息(根据学号sno)
* @param student
* @return true/false
*/
public boolean update(Student student);
2、StudentDaoImpl.java
public class StudentDaoImpl implements StudentDao {
/**
* 插⼊⼀个学⽣
* 插⼊⼀个学⽣
* @param student
* @return
*/
public boolean insert(Student student){
try{
String sql ="insert into student(sName,sno,dpSno,sclass) "+ "values('"
+ sName()
+"',"
+ Sno()
+",'"
+ DpSno()
+"','"
+ Sclass()
+"')";
boolean flag = uteUpdate(sql);
return flag;
mysql面试题 增删改查
}catch(Exception e){
e.printStackTrace();
}
return false;
}
/**
* 查询所有学⽣数据
* @return
*/
public ArrayList<Student>findAllStudent(){
//定义学⽣集合
ArrayList<Student> list =new ArrayList<Student>();
try{
String sql ="select * from student";
ResultSet rs = uteQuery(sql);
//循环遍历结果集并放⼊学⽣集合中
()){
Student student =new Student();
student.String("sName"));
student.Int("sno"));
student.String("dpSno"));
student.String("sclass"));
list.add(student);
}
return list;
}catch(Exception e){
e.printStackTrace();
}
app源码android
return null;
}
// 根据学号查询某个学⽣(前题学号是唯⼀)
public Student findStudentBySno(int sno){
try{
String sql ="select * from student where sno="+ sno;
ResultSet rs = uteQuery(sql);
()){
Student student =new Student();
student.String("sName"));
student.Int("sno"));
student.String("dpSno"));
student.String("sclass"));
return student;
}
return null;
}catch(Exception e){
e.printStackTrace();
}
}
return null;
}
/**
* 根据学号删除学⽣
* @param sno 学号
* @return true/false
*/
public boolean deleteStudentBySno(int sno){
try{
String sql ="delete from student where sno="+ sno;
boolean flag = uteUpdate(sql);
return flag;
}catch(Exception e){
e.printStackTrace();
}
return false;
}
/**
* 更新⼀个学⽣信息(根据学号sno)
* @param student
* @return true/false
*/
public boolean update(Student student){
try{
String sql ="update student set sName='"+ sName()
+"',dpSno='"+DpSno()+"',sclass='"+ Sclass()+"' where sno="+ Sno(); boolean flag = uteUpdate(sql);
return flag;
}catch(Exception e){
e.printStackTrace();
}
return false;
}
}
Entity
1、Student.java

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。