当前位置:   article > 正文

简单学生系统之学生基本信息_学生信息里的title

学生信息里的title


Student.java

  1. package nuc.select.student;
  2. public class Student {
  3. private String scno;
  4. private String sno;
  5. private String sname;
  6. private String ssex;
  7. private int sage;
  8. public String getScno(){
  9. return scno;
  10. }
  11. public void setScno(String scno){
  12. this.scno=scno;
  13. }
  14. public String getSno(){
  15. return sno;
  16. }
  17. public void setSno(String sno){
  18. this.sno=sno;
  19. }
  20. public String getSname(){
  21. return sname;
  22. }
  23. public void setSname(String sname){
  24. this.sname=sname;
  25. }
  26. public String getSsex(){
  27. return ssex;
  28. }
  29. public void setSsex(String ssex){
  30. this.ssex=ssex;
  31. }
  32. public int getSage(){
  33. return sage;
  34. }
  35. public void setSage(int sage){
  36. this.sage=sage;
  37. }
  38. }


Coon.java

  1. package nuc.select.coon;
  2. import java.sql.*;
  3. public class Coon {
  4. public static final String DBDRIVER="org.gjt.mm.mysql.Driver";
  5. public static final String DBURL="jdbc:mysql://localhost:3306/select";
  6. public static final String DBUSER="root";
  7. public static final String DBPASS="*****";
  8. Connection coon=null;
  9. public Connection getCoon(){
  10. try{
  11. Class.forName(DBDRIVER);
  12. coon=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
  13. }catch(Exception e){
  14. e.printStackTrace();
  15. }
  16. return coon;
  17. }
  18. }

StuDao.java

  1. package nuc.select.Dao;
  2. import java.sql.*;
  3. import nuc.select.coon.Coon;
  4. import nuc.select.student.Student;
  5. public class StuDao {
  6. public int Insert(Student student){
  7. int rst=0;
  8. Coon studentcoon=new Coon();
  9. Connection scoona=studentcoon.getCoon();
  10. String sql_insert="insert into student(scno,sno,sname,ssex,sage) values (?,?,?,?,?)";
  11. try {
  12. PreparedStatement pst=scoona.prepareStatement(sql_insert);
  13. pst.setString(1,student.getScno());
  14. pst.setString(2, student.getSno());
  15. pst.setString(3,student.getSname());
  16. pst.setString(4,student.getSsex());
  17. pst.setInt(5,student.getSage());
  18. rst=pst.executeUpdate();
  19. } catch (SQLException e) {
  20. // TODO Auto-generated catch block
  21. e.printStackTrace();
  22. }
  23. return rst;
  24. }
  25. public int Delete(Student student){
  26. int rst=0;
  27. Coon studentcoon=new Coon();
  28. Connection scoona=studentcoon.getCoon();
  29. String sql_delete="delete from student where sno=?";
  30. try {
  31. PreparedStatement pst=scoona.prepareStatement(sql_delete);
  32. pst.setString(1,student.getSno());
  33. rst=pst.executeUpdate();
  34. } catch (SQLException e) {
  35. // TODO Auto-generated catch block
  36. e.printStackTrace();
  37. }
  38. return rst;
  39. }
  40. public ResultSet Query(){
  41. ResultSet rst=null;
  42. Coon studentcoon=new Coon();
  43. Connection scoona=studentcoon.getCoon();
  44. String sql_query="select * from student";
  45. try {
  46. PreparedStatement pst=scoona.prepareStatement(sql_query);
  47. rst=pst.executeQuery();
  48. } catch (SQLException e) {
  49. // TODO Auto-generated catch block
  50. e.printStackTrace();
  51. }
  52. return rst;
  53. }
  54. public int Updates(Student student){
  55. int rst=0;
  56. Coon studentcoon=new Coon();
  57. Connection scoona=studentcoon.getCoon();
  58. String sql_update="update student set scno=?,sname=?,ssex=?,sage=? where sno=?";
  59. try {
  60. PreparedStatement pst=scoona.prepareStatement(sql_update);
  61. pst.setString(1,student.getScno());
  62. pst.setString(2,student.getSname());
  63. pst.setString(3,student.getSsex());
  64. pst.setInt(4,student.getSage());
  65. pst.setString(5,student.getSno());
  66. rst=pst.executeUpdate();
  67. } catch (SQLException e) {
  68. // TODO Auto-generated catch block
  69. e.printStackTrace();
  70. }
  71. return rst;
  72. }
  73. public ResultSet Select(Student student){
  74. ResultSet rst=null;
  75. Coon studentcoon=new Coon();
  76. Connection scoona=studentcoon.getCoon();
  77. String sql_query="select * from student where sno=?";
  78. try {
  79. PreparedStatement pst=scoona.prepareStatement(sql_query);
  80. pst.setString(1,student.getSno());
  81. rst=pst.executeQuery();
  82. } catch (SQLException e) {
  83. // TODO Auto-generated catch block
  84. e.printStackTrace();
  85. }
  86. return rst;
  87. }
  88. }


insertStudent.jsp

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

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

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ page import="java.sql.*" %>
  4. <%@ page import="nuc.select.student.*" %>
  5. <%@ page import="nuc.select.Dao.*" %>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <title>学生基本信息显示</title>
  11. <style type="text/css">
  12. td{
  13. text-align:center;
  14. }
  15. a{
  16. text-decoration:none;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <center>
  22. <%
  23. StuDao stu=new StuDao();
  24. Student stun=new Student();
  25. ResultSet rst=stu.Query();
  26. %>
  27. <table border="1" width="500" height="500">
  28. <caption>学生基本信息表</caption>
  29. <tr><td>班号</td><td>学号</td><td>姓名</td><td>性别</td><td>年龄</td><td colspan="2">数据操作</td></tr>
  30. <%
  31. while(rst.next()){
  32. %>
  33. <tr>
  34. <td><%=rst.getString("scno") %></td>
  35. <td><%=rst.getString("sno") %></td>
  36. <td><%=rst.getString("sname") %></td>
  37. <td><%=rst.getString("ssex") %></td>
  38. <td><%=rst.getString("sage") %></td>
  39. <td><a href="deleteStudent.jsp?sno=<%=rst.getString("sno")%>">删除</a></td>
  40. <td><a href="updateStudent.jsp?sno=<%=rst.getString("sno")%>">修改</a></td>
  41. </tr>
  42. <%
  43. }
  44. %>
  45. </table>
  46. <a href="insertStudent.jsp">添加</a>
  47. </center>
  48. </body>
  49. </html>





声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/316973
推荐阅读
相关标签
  

闽ICP备14008679号