JavaWeb实验五 综合训练至尊版
资源文件列表(大概)
lab6/.settings/.jsdtscope
567B
lab6/.settings/org.eclipse.jdt.core.prefs
364B
lab6/.settings/org.eclipse.wst.common.component
464B
lab6/.settings/org.eclipse.wst.common.project.facet.core.xml
345B
lab6/.settings/org.eclipse.wst.jsdt.ui.superType.container
49B
lab6/.settings/org.eclipse.wst.jsdt.ui.superType.name
6B
lab6/build/classes/bean/
-
lab6/build/classes/bean/Student.class
1.33KB
lab6/build/classes/dao/Impl/
-
lab6/build/classes/dao/Impl/StudentDaoImpl.class
4.8KB
lab6/build/classes/dao/StudentDao.class
515B
lab6/build/classes/service/
-
lab6/build/classes/service/impl/
-
lab6/build/classes/service/impl/StudentServiceImpl.class
1.68KB
lab6/build/classes/service/StudentService.class
527B
lab6/build/classes/servlet/
-
lab6/build/classes/servlet/BaseServlet.class
1.89KB
lab6/build/classes/servlet/StudentServlet.class
3.71KB
lab6/build/classes/util/
-
lab6/build/classes/util/DatabaseBean.class
1.54KB
lab6/src/bean/Student.java
833B
lab6/src/dao/Impl/StudentDaoImpl.java
4.27KB
lab6/src/dao/StudentDao.java
949B
lab6/src/service/impl/StudentServiceImpl.java
1.48KB
lab6/src/service/StudentService.java
622B
lab6/src/servlet/BaseServlet.java
1.02KB
lab6/src/servlet/StudentServlet.java
3.65KB
lab6/src/util/DatabaseBean.java
990B
lab6/WebContent/addStudent.jsp
1.19KB
lab6/WebContent/index.jsp
322B
lab6/WebContent/META-INF/
-
lab6/WebContent/META-INF/MANIFEST.MF
39B
lab6/WebContent/showStudent.jsp
2.06KB
lab6/WebContent/showStudent2.jsp
2.13KB
lab6/WebContent/update.jsp
1.59KB
lab6/WebContent/WEB-INF/
-
lab6/WebContent/WEB-INF/lib/
-
lab6/WebContent/WEB-INF/lib/jstl-1.2.jar
404.53KB
lab6/WebContent/WEB-INF/lib/mysql-connector-java-5.1.20-bin.jar
783.91KB
lab6/WebContent/WEB-INF/lib/mysql-connector-java-8.0.19.jar
2.25MB
lab6/WebContent/WEB-INF/lib/standard-1.1.2.jar
384.04KB
lab6/WebContent/WEB-INF/web.xml
650B
资源内容介绍
【没错,这个就是你要找的学习通的实验!】实验五 综合训练一、实验目的 1.了解MVC思想。2.熟悉Java Web的各种开发技术。二、实验学时4H三、实验性质综合性实验四、实验内容1.创建表t_student,其中包含学号stuno,姓名stuname,性别stusex三个字段,在表中插入一些测试数据。(5分)2.实现下述功能: package dao.Impl;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import bean.Student;import dao.StudentDao;import util.DatabaseBean;public class StudentDaoImpl implements StudentDao {Connection conn = null;PreparedStatement pstmt = null;ResultSet rs = null;@Overridepublic List<Student> findAll() {List<Student> students = new ArrayList<Student>();try {conn = DatabaseBean.getConnection();String sql = "select stuno,stuname,stusex from t_student";pstmt = conn.prepareStatement(sql);rs = pstmt.executeQuery();while (rs.next()) {Student stu = new Student();stu.setStuno(rs.getString("stuno"));stu.setStuname(rs.getString("stuname"));stu.setStusex(rs.getString("stusex"));students.add(stu);}} catch (Exception e) {e.printStackTrace();} finally {DatabaseBean.close(rs, pstmt, conn);}return students;}@Overridepublic List<Student> selectStudentByStuname(String stuname) {// 上转型对象List<Student> students = new ArrayList<Student>();try {conn = DatabaseBean.getConnection();String sql = "select stuno,stuname,stusex from t_student where stuname like ?";pstmt = conn.prepareStatement(sql);pstmt.setString(1, "%" + stuname + "%");rs = pstmt.executeQuery();while (rs.next()) {Student stu = new Student();stu.setStuno(rs.getString("stuno"));stu.setStuname(rs.getString("stuname"));stu.setStusex(rs.getString("stusex"));students.add(stu);}} catch (Exception e) {e.printStackTrace();} finally {DatabaseBean.close(rs, pstmt, conn);}return students;}@Override // 精确查找public Student selectStudentByStuno(String stuno) {Student stu = new Student();try {conn = DatabaseBean.getConnection();// String sql = "SELECT * FROM students WHERE stuno = ?";// 就是因为这条语句是从实验二粘贴过来的,所以导致了后面的错误,终于找出错误了!String sql = "SELECT * FROM t_student WHERE stuno = ?";pstmt = conn.prepareStatement(sql);pstmt.setString(1, stuno);rs = pstmt.executeQuery();while (rs.next()) {stu.setStuno(rs.getString("stuno"));stu.setStuname(rs.getString("stuname"));stu.setStusex(rs.getString("stusex"));}} catch (SQLException e) {e.printStackTrace();} finally {DatabaseBean.close(rs, pstmt, conn);}return stu;}@Overridepublic boolean deleteStudent(String stuno) {try {conn = DatabaseBean.getConnection();String sql = "delete from t_student where stuno=?";pstmt = conn.prepareStatement(sql);pstmt.setString(1, stuno);int result = pstmt.executeUpdate();// pstmt.close();// conn.close();if (result > 0) {return true;}} catch (Exception e) {e.printStackTrace();} finally {DatabaseBean.close(rs, pstmt, conn);}return false;}@Override // 修改学生信息public boolean saveStudent(Student stu) {try {conn = DatabaseBean.getConnection();String sql = "update t_student set stuname=?,stusex=? where stuno=?";pstmt = conn.prepareStatement(sql);pstmt.setString(1, stu.getStuname());pstmt.setString(2, stu.getStusex());pstmt.setString(3, stu.getStuno());int result = pstmt.executeUpdate();// pstmt.close();// conn.close();if (result > 0) {return true;}} catch (Exception e) {e.printStackTrace();} finally {DatabaseBean.close(rs, pstmt, conn);}return false;}@Override // 添加学生信息public boolean addStudent(Student stu) {try {conn = DatabaseBean.getConnection();String sql = "insert into t_student(stuno,stuname,stusex) values(?,?,?)";pstmt = conn.prepareStatement(sql);pstmt.setString(1, stu.getStuno());pstmt.setString(2, stu.getStuname());pstmt.setString(3, stu.getStusex());int result = pstmt.executeUpdate();if (result > 0) {return true;}} catch (Exception e) {e.printStackTrace();} finally {DatabaseBean.close(rs, pstmt, conn);}return false;}}