简单学生系统之学生基本信息

来源:互联网 发布:centos nginx配置文件 编辑:程序博客网 时间:2024/04/28 15:56


Student.java

package nuc.select.student;public class Student {       private String scno;       private String sno;       private String sname;       private String ssex;       private int  sage;       public String getScno(){       return scno;       }       public void setScno(String scno){       this.scno=scno;       }       public String getSno(){       return sno;       }       public void setSno(String sno){       this.sno=sno;       }       public String getSname(){       return sname;       }       public void setSname(String sname){       this.sname=sname;       }       public String getSsex(){       return ssex;       }       public void setSsex(String ssex){       this.ssex=ssex;       }       public int getSage(){       return sage;       }       public void setSage(int sage){       this.sage=sage;       }}


Coon.java

package nuc.select.coon;import java.sql.*;public class Coon {     public static final String DBDRIVER="org.gjt.mm.mysql.Driver";     public static final String DBURL="jdbc:mysql://localhost:3306/select";     public static final String DBUSER="root";     public static final String DBPASS="*****";     Connection coon=null;      public  Connection getCoon(){      try{      Class.forName(DBDRIVER);      coon=DriverManager.getConnection(DBURL,DBUSER,DBPASS);      }catch(Exception e){    e.printStackTrace();      }      return coon;      }    }

StuDao.java

package nuc.select.Dao;import java.sql.*;import nuc.select.coon.Coon;import nuc.select.student.Student;public class StuDao {       public int Insert(Student student){       int rst=0;       Coon studentcoon=new Coon();       Connection scoona=studentcoon.getCoon();        String sql_insert="insert into student(scno,sno,sname,ssex,sage) values (?,?,?,?,?)";       try {PreparedStatement pst=scoona.prepareStatement(sql_insert);pst.setString(1,student.getScno());pst.setString(2, student.getSno());pst.setString(3,student.getSname());pst.setString(4,student.getSsex());pst.setInt(5,student.getSage());rst=pst.executeUpdate();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}       return rst;       }       public int Delete(Student student){       int rst=0;       Coon studentcoon=new Coon();       Connection scoona=studentcoon.getCoon();       String sql_delete="delete from student where sno=?";       try {PreparedStatement pst=scoona.prepareStatement(sql_delete);pst.setString(1,student.getSno());rst=pst.executeUpdate();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}       return rst;       }       public ResultSet Query(){       ResultSet rst=null;       Coon studentcoon=new Coon();       Connection scoona=studentcoon.getCoon();       String sql_query="select * from student";       try {PreparedStatement pst=scoona.prepareStatement(sql_query);rst=pst.executeQuery();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}       return rst;       }       public int Updates(Student student){       int rst=0;       Coon studentcoon=new Coon();       Connection scoona=studentcoon.getCoon();       String sql_update="update student set scno=?,sname=?,ssex=?,sage=? where sno=?";       try {PreparedStatement pst=scoona.prepareStatement(sql_update);pst.setString(1,student.getScno());pst.setString(2,student.getSname());pst.setString(3,student.getSsex());pst.setInt(4,student.getSage());pst.setString(5,student.getSno());rst=pst.executeUpdate();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}       return rst;       }       public ResultSet Select(Student student){       ResultSet rst=null;       Coon studentcoon=new Coon();       Connection scoona=studentcoon.getCoon();       String sql_query="select * from student where sno=?";       try {PreparedStatement pst=scoona.prepareStatement(sql_query);pst.setString(1,student.getSno());rst=pst.executeQuery();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}       return rst;       }}


insertStudent.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><form action="doinsertStudent.jsp" method="post">班号<input type="text" name="scno">   学号<input type="text" name="sno">   姓名<input type="text" name="sname">   性别<input type="text" name="ssex">   年龄<input type="text" name="sage">   <input type="submit" value="添加"><input type="reset" value="重置"></form></body></html>
doinsertStudent.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>    <%@ page import="java.sql.*" %>    <%@ page import="nuc.select.student.*" %>    <%@ page import="nuc.select.Dao.*" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><%request.setCharacterEncoding("utf-8"); %><jsp:useBean id="students" class="nuc.select.student.Student"><jsp:setProperty name="students" property="*"/></jsp:useBean><%      StuDao stu=new StuDao();      Student stun=new Student();      int rt=stu.Insert(students);      if(rt>0){      out.println("添加成功!");      }      else{      out.println("添加失败!");      }%></body></html>
deleteStudent.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>    <%@ page import="java.sql.*" %>    <%@ page import="nuc.select.student.*" %>    <%@ page import="nuc.select.Dao.*" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><%    StuDao stu=new StuDao();    Student stun=new Student();    stun.setSno(request.getParameter("sno"));    int rst=stu.Delete(stun);    if(rst>0){    out.println("删除成功!");    }else{    out.println("删除失败!");    }%></body></html>
updateStudent.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>    <%@ page import="java.sql.*" %>    <%@ page import="nuc.select.student.*" %>    <%@ page import="nuc.select.Dao.*" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body> <%     request.setCharacterEncoding("utf-8");StuDao stu=new StuDao(); Student stun=new Student(); stun.setSno(request.getParameter("sno")); ResultSet rst=stu.Select(stun); if(rst.next()){ %> <form action="doupdateStudent.jsp?sno=<%=rst.getString("sno") %>" method="post">班号<input type="text" name="scno" value="<%=rst.getString("scno")%>">   学号<input type="text" name="sno" value="<%=rst.getString("sno")%>">   姓名<input type="text" name="sname" value="<%=rst.getString("sname")%>">   性别<input type="text" name="ssex" value="<%=rst.getString("ssex")%>">   年龄<input type="text" name="sage" value="<%=rst.getInt("sage")%>">   <input type="submit" value="修改"><input type="reset" value="取消"></form> <%} %></body></html>
doupdateStudent.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>    <%@ page import="java.sql.*" %>    <%@ page import="nuc.select.student.*" %>    <%@ page import="nuc.select.Dao.*" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body><% request.setCharacterEncoding("utf-8"); %><jsp:useBean id="std" class="nuc.select.student.Student"><jsp:setProperty name="std" property="*" /></jsp:useBean><%StuDao stu=new StuDao();Student stun=new Student();stun.setSno(request.getParameter("sno"));int rst=stu.Updates(std);if(rst>0){out.println("修改成功!");}else{out.println("修改失败!");}%></body></html>
queryStudent.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>    <%@ page import="java.sql.*" %>    <%@ page import="nuc.select.student.*" %>    <%@ page import="nuc.select.Dao.*" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>学生基本信息显示</title><style type="text/css">td{  text-align:center;}a{  text-decoration:none;}</style></head><body><center><%        StuDao stu=new StuDao();       Student stun=new Student();       ResultSet rst=stu.Query();%><table border="1" width="500" height="500"><caption>学生基本信息表</caption><tr><td>班号</td><td>学号</td><td>姓名</td><td>性别</td><td>年龄</td><td colspan="2">数据操作</td></tr><%    while(rst.next()){%><tr><td><%=rst.getString("scno") %></td><td><%=rst.getString("sno") %></td><td><%=rst.getString("sname") %></td><td><%=rst.getString("ssex") %></td><td><%=rst.getString("sage") %></td><td><a href="deleteStudent.jsp?sno=<%=rst.getString("sno")%>">删除</a></td><td><a href="updateStudent.jsp?sno=<%=rst.getString("sno")%>">修改</a></td></tr><%        }%></table><a href="insertStudent.jsp">添加</a></center></body></html>