IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统(下)

本文涉及的产品
RDS SQL Server Serverless,2-4RCU 50GB 3个月
推荐场景:
云数据库 RDS SQL Server,基础系列 2核4GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
简介: IDEA+Java+Jsp+Mysql实现Web毕业设计选题系统

TeacherManager


教师信息管理类,实现教师信息的增加,查看,删除。

package com.sjsq.service;
import com.sjsq.model.Teacher;
import com.sjsq.util.DB;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class TeacherManager {
    public static boolean save(Teacher te) {
        Connection conn = DB.getConn();
        String sql = null;
        boolean b = false;
        sql = "insert into teacher_info values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        PreparedStatement pstmt = DB.prepare(conn, sql);
        try {
            pstmt.setString(1, te.getNumber());
            pstmt.setString(2, te.getName());
            pstmt.setString(3, te.getSex());
            pstmt.setString(4, te.getDept());
            pstmt.setString(5, te.getDegree());
            pstmt.setString(6, te.getTitle());
            pstmt.setShort(7, te.getRight());
            pstmt.setString(8, te.getPhone());
            pstmt.setString(9, te.getEmail());
            pstmt.setString(10, te.getGroup());
            pstmt.setString(11, te.getPassword());
            pstmt.execute();
            b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(pstmt);
            DB.close(conn);
        }
        return b;
    }
    public static int getTeachers(List<Teacher> teachers, int pageNo,
                                  int pageSize) {
        int totalRecords = -1;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from teacher_info limit " + (pageNo - 1) * pageSize
                + "," + pageSize;
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Statement stmtCount = DB.getStatement(conn);
        ResultSet rsCount = null;
        rsCount = DB.getResultSet(stmtCount,
                "select count(*) from teacher_info");
        try {
            rsCount.next();
            totalRecords = rsCount.getInt(1);
            while (rs.next()) {
                Teacher teacher = new Teacher();
                teacher.setEmail(rs.getString("temail"));
                teacher.setGroup(rs.getString("tgroup"));
                teacher.setName(rs.getString("tname"));
                teacher.setNumber(rs.getString("tno"));
                teacher.setPassword(rs.getString("tpassword"));
                teacher.setPhone(rs.getString("ttel"));
                teacher.setDept(rs.getString("tdept"));
                teacher.setSex(rs.getString("tsex"));
                teacher.setDegree(rs.getString("tdegree"));
                teacher.setRight(rs.getShort("tright"));
                teacher.setTitle(rs.getString("ttitle"));
                teachers.add(teacher);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rsCount);
            DB.close(stmtCount);
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }
        return totalRecords;
    }
    public static boolean deleteByTno(String id) {
        boolean b = false;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "delete from teacher_info where tno = '" + id + "'";
        Statement stmt = DB.getStatement(conn);
        try {
            DB.executeUpdate(stmt, sql);
            b = true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DB.close(stmt);
            DB.close(conn);
        }
        return b;
    }
    public static Teacher check(String num, String password)
            throws UserNotFoundException, PasswordNotCorrectException {
        Teacher teacher = null;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from teacher_info where tno = '" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        try {
            if (!rs.next()) {
                throw new UserNotFoundException("用户不存在:" + num);
            } else {
                if (!password.equals(rs.getString("tpassword"))) {
                    throw new PasswordNotCorrectException("密码不正确!");
                }
            }
            teacher = new Teacher();
            teacher.setEmail(rs.getString("temail"));
            teacher.setGroup(rs.getString("tgroup"));
            teacher.setName(rs.getString("tname"));
            teacher.setNumber(rs.getString("tno"));
            teacher.setPassword(rs.getString("tpassword"));
            teacher.setPhone(rs.getString("ttel"));
            teacher.setDept(rs.getString("tdept"));
            teacher.setSex(rs.getString("tsex"));
            teacher.setDegree(rs.getString("tdegree"));
            teacher.setRight(rs.getShort("tright"));
            teacher.setTitle(rs.getString("ttitle"));
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }
        return teacher;
    }
    public static Teacher getByTno(String num) {
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from teacher_info where tno='" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Teacher teacher = null;
        try {
            if (rs.next()) {
                teacher = new Teacher();
                teacher.setEmail(rs.getString("temail"));
                teacher.setGroup(rs.getString("tgroup"));
                teacher.setName(rs.getString("tname"));
                teacher.setNumber(rs.getString("tno"));
                teacher.setPassword(rs.getString("tpassword"));
                teacher.setPhone(rs.getString("ttel"));
                teacher.setDept(rs.getString("tdept"));
                teacher.setSex(rs.getString("tsex"));
                teacher.setDegree(rs.getString("tdegree"));
                teacher.setRight(rs.getShort("tright"));
                teacher.setTitle(rs.getString("ttitle"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return teacher;
    }
    public static boolean update(Teacher te) {
        Connection conn = DB.getConn();
        String sql = null;
        boolean b = false;
        sql = "update teacher_info set tpassword=?, tgroup=?, tname=?, tsex=?, ttel=?, temail=?, tdept=?, ttitle=?, tright=?,  tdegree=? where tno = ?";
        PreparedStatement pstmt = DB.prepare(conn, sql);
        try {
            pstmt.setString(1, te.getPassword());
            pstmt.setString(2, te.getGroup());
            pstmt.setString(3, te.getName());
            pstmt.setString(4, te.getSex());
            pstmt.setString(5, te.getPhone());
            pstmt.setString(6, te.getEmail());
            pstmt.setString(7, te.getDept());
            pstmt.setString(8, te.getTitle());
            pstmt.setShort(9, te.getRight());
            pstmt.setString(10, te.getDegree());
            pstmt.setString(11, te.getNumber());
            pstmt.executeUpdate();
            b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(pstmt);
            DB.close(conn);
        }
        return b;
    }
    public static int query(List<Teacher> teachers, int pageNo, int pageSize,
                            String dept, String num, String name) {
        int totalRecords = -1;
        Connection conn = DB.getConn();
        String sql = null;
        if (dept == null)
            dept = "";
        if (name == null)
            name = "";
        if (num == null)
            num = "";
        sql = "select * from teacher_info where tdept like '%" + dept
                + "%' and tname like '%" + name + "%' and tno like '%" + num
                + "%'";
        sql += "limit " + (pageNo - 1) * pageSize + "," + pageSize;
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Statement stmtCount = DB.getStatement(conn);
        ResultSet rsCount = null;
        rsCount = DB.getResultSet(stmtCount,
                "select count(*) from teacher_info where tdept like '%" + dept
                        + "%' and tname like '%" + name + "%' and tno like '%"
                        + num + "%'");
        try {
            rsCount.next();
            totalRecords = rsCount.getInt(1);
            while (rs.next()) {
                Teacher teacher = new Teacher();
                teacher.setEmail(rs.getString("temail"));
                teacher.setGroup(rs.getString("tgroup"));
                teacher.setName(rs.getString("tname"));
                teacher.setNumber(rs.getString("tno"));
                teacher.setPassword(rs.getString("tpassword"));
                teacher.setPhone(rs.getString("ttel"));
                teacher.setDept(rs.getString("tdept"));
                teacher.setSex(rs.getString("tsex"));
                teacher.setDegree(rs.getString("tdegree"));
                teacher.setRight(rs.getShort("tright"));
                teacher.setTitle(rs.getString("ttitle"));
                teachers.add(teacher);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rsCount);
            DB.close(stmtCount);
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }
        return totalRecords;
    }
    public static List<String> adds(String file) {
        Connection conn = DB.getConn();
        Workbook info;
        List<String> tnumber = new ArrayList<String>();
        String sql = "insert into teacher_info values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        try {
            info = Workbook.getWorkbook(new FileInputStream(file));
            Sheet sheet = info.getSheet(0);
            int size = sheet.getRows();
            for (int i = 1; i < size; i++) {
                Cell c = sheet.getCell(0, i);
                if (TeacherManager.getByTno(c.getContents().trim()) != null) {
                    tnumber.add(c.getContents().trim());
                    continue;
                }
                PreparedStatement pstmt = DB.prepare(conn, sql);
                for (int j = 0; j < 11; j++) {
                    c = sheet.getCell(j, i);
                    if (j != 6) {
                        pstmt.setString(j + 1, c.getContents().trim());
                    } else
                        pstmt.setShort(j + 1, Short.parseShort(c.getContents()));
                }
                pstmt.execute();
            }
        } catch (BiffException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return tnumber;
    }
}

TopicManager


选题信息管理,实现选题新的增加,修改,查看,删除。

package com.sjsq.service;
import com.sjsq.model.Topic;
import com.sjsq.util.DB;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class TopicManager {
    public static boolean save(Topic t) {
        Connection conn = DB.getConn();
        String sql = null;
        boolean b = false;
        sql = "insert into topic_info values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        PreparedStatement pstmt = DB.prepare(conn, sql);
        try {
            pstmt.setString(1, t.getNumber());
            pstmt.setString(2, t.getName());
            pstmt.setString(3, t.getType());
            pstmt.setString(4, t.getKind());
            pstmt.setString(5, t.getSource());
            pstmt.setString(6, t.getStatus());
            pstmt.setString(7, t.getContent());
            pstmt.setString(8, t.getResult());
            pstmt.setString(9, t.getDirection());
            pstmt.setString(10, t.getTnumber());
            pstmt.setString(11, t.getSnumber());
            pstmt.execute();
            b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(pstmt);
            DB.close(conn);
        }
        return b;
    }
    public static int getTopics(List<Topic> topics, int pageNo,
                                int pageSize) {
        int totalRecords = -1;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from topic_info limit " + (pageNo - 1) * pageSize
                + "," + pageSize;
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Statement stmtCount = DB.getStatement(conn);
        ResultSet rsCount = null;
        rsCount = DB
                .getResultSet(stmtCount, "select count(*) from topic_info");
        try {
            rsCount.next();
            totalRecords = rsCount.getInt(1);
            while (rs.next()) {
                Topic topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
                topics.add(topic);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rsCount);
            DB.close(stmtCount);
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }
        return totalRecords;
    }
    public static boolean deleteByHno(String hno) {
        boolean b = false;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "delete from topic_info where hno = '" + hno + "'";
        Statement stmt = DB.getStatement(conn);
        try {
            DB.executeUpdate(stmt, sql);
            b = true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DB.close(stmt);
            DB.close(conn);
        }
        return b;
    }
    public static boolean check(String tno, String hname) {
        boolean b = false;
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from topic_info where tno = '" + tno + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        try {
            if (rs.next()) b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }
        return b;
    }
    public static boolean update(Topic t) {
        Connection conn = DB.getConn();
        String sql = null;
        boolean b = false;
        sql = "update topic_info set htype=?, tno=?, hname=?, hsource=?, hkind=?, hstatus=?, hresult=?, sno=?, direction=?,  hcontent=? where hno = ?";
        PreparedStatement pstmt = DB.prepare(conn, sql);
        try {
            pstmt.setString(1, t.getType());
            pstmt.setString(2, t.getTnumber());
            pstmt.setString(3, t.getName());
            pstmt.setString(4, t.getSource());
            pstmt.setString(5, t.getKind());
            pstmt.setString(6, t.getStatus());
            pstmt.setString(7, t.getResult());
            pstmt.setString(8, t.getSnumber());
            pstmt.setString(9, t.getDirection());
            pstmt.setString(10, t.getContent());
            pstmt.setString(11, t.getNumber());
            pstmt.executeUpdate();
            b = true;
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(pstmt);
            DB.close(conn);
        }
        return b;
    }
    public static Topic getByNum(String num) {
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from topic_info where hno='" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Topic topic = null;
        try {
            if (rs.next()) {
                topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return topic;
    }
    public static List<Topic> getByTno(String num) {
        Connection conn = DB.getConn();
        String sql = null;
        List<Topic> topics = new ArrayList<Topic>();
        sql = "select * from topic_info where tno='" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Topic topic = null;
        try {
            while (rs.next()) {
                topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
                topics.add(topic);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return topics;
    }
    public static int query(List<Topic> topics, int pageNo, int pageSize, String str, String kind, String name) {
        int totalRecords = -1;
        Connection conn = DB.getConn();
        String sql = null;
        if (str == null)
            str = "";
        if (kind == null)
            kind = "";
        if (name == null)
            name = "";
        sql = "select * from topic_info where hname like '%" + name
                + "%' and htype like '%" + str + "%' and hkind like '%" + kind + "%'";
        sql += "limit " + (pageNo - 1) * pageSize + "," + pageSize;
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Statement stmtCount = DB.getStatement(conn);
        ResultSet rsCount = null;
        rsCount = DB
                .getResultSet(stmtCount, "select count(*) from topic_info where hname like '%" + name
                        + "%' and htype like '%" + str + "%' and hkind like '%" + kind + "%'");
        try {
            if (rsCount != null) rsCount.next();
            totalRecords = rsCount.getInt(1);
            while (rs.next()) {
                Topic topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
                topics.add(topic);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rsCount);
            DB.close(stmtCount);
            DB.close(rs);
            DB.close(stmt);
            DB.close(conn);
        }
        return totalRecords;
    }
    public static List<Topic> getByStatus(String num) {
        Connection conn = DB.getConn();
        List<Topic> topics = new ArrayList<Topic>();
        String sql = null;
        sql = "select * from topic_info where hstatus='" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Topic topic = null;
        try {
            while (rs.next()) {
                topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
                topics.add(topic);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return topics;
    }
    public static Topic getBySnum(String num) {
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from topic_info where sno='" + num + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Topic topic = null;
        try {
            if (rs.next()) {
                topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return topic;
    }
    public static Topic getByTnumAndHname(String tnum, String hname) {
        Connection conn = DB.getConn();
        String sql = null;
        sql = "select * from topic_info where tno='" + tnum + "' and hname='" + hname + "'";
        Statement stmt = DB.getStatement(conn);
        ResultSet rs = DB.getResultSet(stmt, sql);
        Topic topic = null;
        try {
            if (rs.next()) {
                topic = new Topic();
                topic.setContent(rs.getString("hcontent"));
                topic.setDirection(rs.getString("direction"));
                topic.setKind(rs.getString("hkind"));
                topic.setName(rs.getString("hname"));
                topic.setNumber(rs.getString("hno"));
                topic.setResult(rs.getString("hresult"));
                topic.setSnumber(rs.getString("sno"));
                topic.setSource(rs.getString("hsource"));
                topic.setStatus(rs.getString("hstatus"));
                topic.setType(rs.getString("htype"));
                topic.setTnumber(rs.getString("tno"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DB.close(rs);
            DB.close(conn);
        }
        return topic;
    }
}

DB


数据库连接类

package com.sjsq.util;
import java.sql.*;
/**
 *
 * 对数据库连接的封装
 *
 */
public class DB {
  /**
   * 获得对要用的数据库的连接
   * @return 返回数据库的连接
   */
  public static Connection getConn() {
    Connection conn = null;
    try {
      Class.forName("com.mysql.cj.jdbc.Driver");//数据库的驱动类 若数据库为sqlserver 应为: ("com.microsoft.sqlserver.jdbc.SQLServerDriver")
      conn = DriverManager.getConnection("jdbc:mysql://localhost/jsp_select_topic?serverTimezone=UTC","root","admin");
      //jdbc:myseql数据库的类型  localhost:3306本机3306端口 select_course 数据库名 user=root 用户名为root password=root 用户密码为root
      // 若是sqlserver应为("jdbc:sqlserver://localhst:1422;databaseName=select_course", "root", "root");
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return conn;
  }
  /**
   * 获得多数据库的预编译的 SQL 语句的对象
   * @param conn 数据库的连接
   * @param sql 要执行的SQL语句
   * @return 返回预编译的 SQL 语句的对象
   */
  public static PreparedStatement prepare(Connection conn,  String sql) {
    PreparedStatement pstmt = null;
    try {
      if(conn != null) {
        pstmt = conn.prepareStatement(sql);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return pstmt;
  }
  /**
   *
   * @param conn 数据库的连接
   * @return 返回执行静态 SQL 语句对象
   */
  public static Statement getStatement(Connection conn) {
    Statement stmt = null;
    try {
      if(conn != null) {
        stmt = conn.createStatement();
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return stmt;
  }
  /**
   *
   * @param stmt 执行静态SQl语句的对象
   * @param sql 要执行的SQL语句
   * @return 执行后的结果集
   */
  public static ResultSet getResultSet(Statement stmt, String sql) {
    ResultSet rs = null;
    try {
      if(stmt != null) {
        rs = stmt.executeQuery(sql);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return rs;
  }
  /**
   *
   * @param stmt 静态执行sql语句的对象
   * @param sql 要执行的SQL语句
   */
  public static void executeUpdate(Statement stmt, String sql) {
    try {
      if(stmt != null) {
        stmt.executeUpdate(sql);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
  /**
   * 关闭数据库的连接
   * @param conn 数据库的连接
   */
  public static void close(Connection conn) {
    try {
      if(conn != null) {
        conn.close();
        conn = null;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
  /**
   * 关闭Statement
   * @param stmt
   */
  public static void close(Statement stmt) {
    try {
      if(stmt != null) {
        stmt.close();
        stmt = null;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
  /**
   * 关闭ResultSet
   * @param rs
   */
  public static void close(ResultSet rs) {
    try {
      if(rs != null) {
        rs.close();
        rs = null;
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
}

Login.jsp


登录前端页面,实现用户登录,判断用户类型,调用登录函数。

<%@ page language="java" import="com.sjsq.model.Student" pageEncoding="UTF-8" %>
<%@ page import="com.sjsq.model.Teacher" %>
<%@ page import="com.sjsq.service.PasswordNotCorrectException" %>
<%@ page import="com.sjsq.service.StudentManager" %>
<%@ page import="com.sjsq.service.TeacherManager" %>
<%@ page import="com.sjsq.service.UserNotFoundException" %>
<%
    String username = request.getParameter("user_no").trim();
    String password = request.getParameter("user_pass").trim();
    int type = Integer.parseInt(request.getParameter("u_type").trim());
    try {
        if (type == 1) {
            Student student = StudentManager.check(username, password);
            session.setAttribute("user", student);
            session.setAttribute("type", type);
            response.sendRedirect("student/student.jsp");
        }
        if (type == 2) {
            Teacher teacher = TeacherManager.check(username, password);
            session.setAttribute("user", teacher);
            session.setAttribute("type", type);
            response.sendRedirect("teacher/teacher.jsp");
        }
        if (type == 3) {
            Teacher teacher = TeacherManager.check(username, password);
            if (teacher.getRight() == 0) {
                session.setAttribute("user", teacher);
                session.setAttribute("type", type);
                response.sendRedirect("admin/admin.jsp");
            } else {
                out.println("您没有管理员权限!");
                return;
            }
        }
    } catch (UserNotFoundException e) {
        out.println(e.getMessage());
        return;
    } catch (PasswordNotCorrectException e) {
        out.println(e.getMessage());
        return;
    }
%>

index.jsp


用户登录界面

<%@page pageEncoding="UTF-8" %>
<%@page import="com.sjsq.service.MsgManager" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>毕业设计选题系统-用户登录</title>
    <link href="js/css.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        .STYLE4 {
            color: #FFFFFF;
            font-family: "楷体_GB2312";
            font-size: 24px;
            font-weight: bold;
        }
        .STYLE5 {
            color: #FFFFFF;
            font-weight: bold;
            font-size: 16px;
        }
        .STYLE7 {
            color: #0000FF;
            font-size: 16px;
        }
        .STYLE3 {
            font-size: 12px;
            color: #FFFFFF;
            text-decoration: none;
        }
    </style>
    <script language="javascript" type="text/javascript">
        function CheckForm() {
            if (document.login.user_no.value.length == 0) {
                alert("请输入用户编号,学生为8位数的学号!");
                document.login.user_no.focus();
                return false;
            }
            return true;
        }
    </script>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
<body class="bg">
<table width="100%" height="100%" border="0" cellpadding="0"
       cellspacing="0">
    <tr>
        <td align="center" valign="middle">
            <table width="817" height="384" border="0" cellpadding="0"
                   cellspacing="0" background="images/login.jpg">
                <tr>
                    <td>&nbsp;</td>
                    <td>
                        <p align="left">
                            <br> <br> <br>
                        </p>
                        <table width="95%" height="14" border="0" align="left"
                               cellpadding="0" cellspacing="0">
                            <tr>
                                <td><span class="STYLE4">毕业设计选题系统</span></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td width="100">&nbsp;</td>
                    <td height="239">
                        <form id="login" name="login" method="post" action="Login.jsp"
                              onSubmit="return CheckForm();">
                            <table width="85%" border="0" align="left" cellspacing="3">
                                <tr>
                                    <td class="FontWit">&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td class="STYLE3">
                                        <div align="center" class="STYLE5"></div>
                                    </td>
                                    <td width="44%" rowspan="5" class="STYLE3">
                                        <MARQUEE
                                                style="WIDTH: 220; HEIGHT: 180; color:red;" scrollAmount=1
                                                scrollDelay=77 direction=up width=280 height=200
                                                onMouseOut="this.start()" onMouseOver="this.stop()">
                                            <%
                                                String[] title = MsgManager.getTitles();
                                                for (int i = 0; title[i] != null; i++) {
                                            %>
                                            <p>
                                                <a href="news.jsp?id=<%=title[i]%>" target="_blank"
                                                   style="color: red;"><%=title[i]%>
                                                </a>
                                            </p>
                                            <%
                                                }
                                            %>
                                        </MARQUEE>
                                    </td>
                                </tr>
                                <tr>
                                    <td width="20%" class="FontWit">
                                        <div align="right">用户编号:</div>
                                    </td>
                                    <td width="34%">
                                        <div align="left">
                                            <input name="user_no" type="text" id="user_no" size="18"
                                                   <%--title="用户名或编号,学生为学号!"/> <span class="FontWit"--%>
                                                                                 <%--title="姓名或编号(学生为学号)">提示</span>--%>
                                        </div>
                                    </td>
                                    <td width="8%" class="STYLE3">
                                        <div align="center">
                                            <span class="STYLE5">公</span>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="FontWit">
                                        <div align="right">用户密码:</div>
                                    </td>
                                    <td>
                                        <div align="left">
                                            <input name="user_pass" type="password" id="user_pass"
                                                   size="18" title="默认密码是admin,登录后请自行修改!"/>
                                            <%--<span class="FontWit" title="默认密码是admin,登录后请自行修改!">提示</span>--%>
                                        </div>
                                       </td>
                                    <td class="STYLE3">
                                        <div align="center">
                                            <span class="STYLE5">告</span>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="FontWit">
                                        <div align="right">用户类型:</div>
                                    </td>
                                    <td>
                                        <div align="left">
                                            <select name="u_type" id="u_type">
                                                <option value="1">学 生</option>
                                                <option value="2">教师</option>
                                                <option value="3">管理员</option>
                                            </select>
                                        </div>
                                    </td>
                                    <td class="STYLE3">
                                        <div align="center">
                                            <span class="STYLE5">通</span>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="24" class="FontWit">
                                        <div align="right"></div>
                                    </td>
                                    <td>
                                        <div align="left">
                                            <input type="submit" name="Submit" value=" 登 录 "/> <input
                                                type="reset" name="Submit2" value=" 重 置 ">
                                        </div>
                                    </td>
                                    <td class="STYLE3">
                                        <div align="center">
                                            <span class="STYLE5">知</span>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="72"></td>
                                    <td></td>
                                    <td colspan="2"></td>
                                </tr>
                            </table>
                        </form>
                    </td>
                </tr>
            </table>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td>
                        <div align="center" class="FontWit">
                            <TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
                                <TBODY>
                                <TR>
                                    <TD>
                                        <DIV align="center" class="FontWit">
                                            <p>
                                                2022-2022 XXX软件开发有限技术公司<A href="" target="_blank" class="STYLE3"></A>
                                                <%--<a target="_blank"--%>
                                                         <%--href="http://wpa.qq.com/msgrd?v=3&uin=3079118617&site=qq&menu=yes"><img--%>
                                                    <%--border="0" src="http://wpa.qq.com/pa?p=2:287433220:41"--%>
                                                    <%--alt="点击这里给我发消息" title="点击这里给我发消息"> </a> <br>--%>
                                            </p>
                                        </DIV>
                                    </TD>
                                </TR>
                                </TBODY>
                            </TABLE>
                        </div>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
</body>
</html>

news.jsp


新闻公告界面

<%@page pageEncoding="UTF-8" import="com.sjsq.service.MsgManager" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
    <link rel="stylesheet" href="../js/CssAdmin.css">
    <title>公告详情</title>
</head>
<body>
<table width="100%" border="0" cellpadding="3" cellspacing="1"
       bgcolor="#6298E1">
    <tr>
        <td height="24" nowrap>
            <font color="#FFFFFF"><img src="images/Explain.gif"
                                       width="18" height="18" border="0" align="absmiddle"> &nbsp;<strong>公告详情</strong>
            </font>
        </td>
    </tr>
</table>
<center>
    <br/>
    <%
        String number = new String(request.getParameter("id").getBytes("UTF-8"), "UTF-8");
        String text = MsgManager.getTexts(number);
    %>
    <table width="100%" border="0" cellpadding="3" cellspacing="1"
           bgcolor="#6298E1">
        <tr>
            <td height="24" nowrap bgcolor="#EBF2F9">
                <table width="100%" border="0" cellpadding="0" cellspacing="0"
                       id="editProduct" idth="100%">
                    <tr>
                        <td width="120" height="20" align="right">
                            &nbsp;
                        </td>
                        <td>
                            <div align="left"></div>
                        </td>
                    </tr>
                    <tr>
                        <td height="20" align="right">
                            标题:
                        </td>
                        <td>
                            <div align="center">
                                <%=number%>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td height="20" align="right">
                            内容:
                        </td>
                        <td>
                            <div align="center">
                                <%=text%>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</center>
</body>
</html>


四、其他


1.更多系统


Java+JSP系统系列实现


Java+JSP实现学生图书管理系统


Java+JSP实现学生信息管理系统


Java+JSP实现用户信息管理系统


Java+JSP实现教师信息管理系统


Java+JSP实现学生宿舍管理系统


Java+JSP实现商品信息管理系统


Java+JSP实现宠物信息管理系统


Java+JSP实现学生成绩管理系统


Java+Servlet系统系列实现

Java+Servlet+JSP实现航空订票系统


Java+Servlet+JSP实现新闻发布系统


Java+Servlet+JSP学生宿舍管理系统


Java+Servlet+JSP实现图书管理系统


Java+Servlet+JSP实现停车场管理系统


Java+Servlet+JSP实现房屋租赁管理系统


Java+Servlet+JSP实现学生信息管理系统


Java+Servlet+JSP实现学生选课管理系统


Java+Servlet+JSPl实现学生选课签到系统


Java+Servlet+JSP实现宠物诊所管理系统


Java+Servlet+JSP实现学生成绩管理系统-1


Java+Servlet+JSP实现学生成绩管理系统-2


Java+SSM系统系列实现

Java+SSM+JSP实现网上考试系统


Java+SSM+JSP实现宠物商城系统


Java+SSM+JSP实现超市管理系统


Java+SSM+JSP实现学生成绩管理系统


Java+SSM+JSP实现学生信息管理系统


Java+SSM+JSP实现药品信息管理系统


Java+SSM+JSP实现汽车信息管理系统


Java+SSM+Jspl实现商品信息管理系统


Java+SSM+JSP+Maven实现网上书城系统


Java+SSM+JSP+Maven实现学校教务管理系统


Java+SSH系统系列实现

Java+SSH+JSP实现在线考试系统


Java+SSH+JSP实现医院在线挂号系统


Java+Springboot系统系列实现

Java+Springboot+H-ui+Maven实现营销管理系统


Java+Springboot+Bootstrap+Maven实现网上商城系统


Java+Springboot+Bootstrap+Maven实现景区旅游管理系统


1.更多JavaWeb系统请关注专栏。


https://blog.csdn.net/helongqiang/category_10020130.html

https://blog.csdn.net/helongqiang/category_10020130.html


2.更多JavaSwing系统请关注专栏。


https://blog.csdn.net/helongqiang/category_6229101.html

https://blog.csdn.net/helongqiang/category_6229101.html


2.源码下载

sql在sql文件夹下面


系统账号信息


1.管理员


账号:101  密码:admin


2.教师


账号:102  密码:123456


3.学生


账号:1001 密码:123456


Java+Jsp+Mysql实现Web毕业设计选题系统


3.运行项目

关注B站:水坚石青


后期有更多干货视频推出!!!


IDEA如何导入JavaWeb项目超详细视频教程


4.备注

如有侵权请联系我删除。


5.支持博主

如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!


相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
10天前
|
运维 自然语言处理 供应链
Java云HIS医院管理系统源码 病案管理、医保业务、门诊、住院、电子病历编辑器
通过门诊的申请,或者直接住院登记,通过”护士工作站“分配患者,完成后,进入医生患者列表,医生对应开具”长期医嘱“和”临时医嘱“,并在电子病历中,记录病情。病人出院时,停止长期医嘱,开具出院医嘱。进入出院审核,审核医嘱与住院通过后,病人结清缴费,完成出院。
35 3
|
13天前
|
Java 数据库连接 数据库
深入探讨Java连接池技术如何通过复用数据库连接、减少连接建立和断开的开销,从而显著提升系统性能
在Java应用开发中,数据库操作常成为性能瓶颈。本文通过问题解答形式,深入探讨Java连接池技术如何通过复用数据库连接、减少连接建立和断开的开销,从而显著提升系统性能。文章介绍了连接池的优势、选择和使用方法,以及优化配置的技巧。
16 1
|
15天前
|
JavaScript Java 项目管理
Java毕设学习 基于SpringBoot + Vue 的医院管理系统 持续给大家寻找Java毕设学习项目(附源码)
基于SpringBoot + Vue的医院管理系统,涵盖医院、患者、挂号、药物、检查、病床、排班管理和数据分析等功能。开发工具为IDEA和HBuilder X,环境需配置jdk8、Node.js14、MySQL8。文末提供源码下载链接。
|
存储 Java 关系型数据库
Java数据类型和MySql数据类型对应表
java mysql 数据类型对照 类型名称 显示长度 数据库类型 JAVA类型 JDBC类型索引(int) 描述             VARCHAR L+N VARCHAR java.
2162 0
|
5天前
|
安全 Java 测试技术
Java并行流陷阱:为什么指定线程池可能是个坏主意
本文探讨了Java并行流的使用陷阱,尤其是指定线程池的问题。文章分析了并行流的设计思想,指出了指定线程池的弊端,并提供了使用CompletableFuture等替代方案。同时,介绍了Parallel Collector库在处理阻塞任务时的优势和特点。
|
14天前
|
安全 Java
java 中 i++ 到底是否线程安全?
本文通过实例探讨了 `i++` 在多线程环境下的线程安全性问题。首先,使用 100 个线程分别执行 10000 次 `i++` 操作,发现最终结果小于预期的 1000000,证明 `i++` 是线程不安全的。接着,介绍了两种解决方法:使用 `synchronized` 关键字加锁和使用 `AtomicInteger` 类。其中,`AtomicInteger` 通过 `CAS` 操作实现了高效的线程安全。最后,通过分析字节码和源码,解释了 `i++` 为何线程不安全以及 `AtomicInteger` 如何保证线程安全。
java 中 i++ 到底是否线程安全?
|
2天前
|
安全 Java 开发者
深入解读JAVA多线程:wait()、notify()、notifyAll()的奥秘
在Java多线程编程中,`wait()`、`notify()`和`notifyAll()`方法是实现线程间通信和同步的关键机制。这些方法定义在`java.lang.Object`类中,每个Java对象都可以作为线程间通信的媒介。本文将详细解析这三个方法的使用方法和最佳实践,帮助开发者更高效地进行多线程编程。 示例代码展示了如何在同步方法中使用这些方法,确保线程安全和高效的通信。
15 9
|
5天前
|
存储 安全 Java
Java多线程编程的艺术:从基础到实践####
本文深入探讨了Java多线程编程的核心概念、应用场景及其实现方式,旨在帮助开发者理解并掌握多线程编程的基本技能。文章首先概述了多线程的重要性和常见挑战,随后详细介绍了Java中创建和管理线程的两种主要方式:继承Thread类与实现Runnable接口。通过实例代码,本文展示了如何正确启动、运行及同步线程,以及如何处理线程间的通信与协作问题。最后,文章总结了多线程编程的最佳实践,为读者在实际项目中应用多线程技术提供了宝贵的参考。 ####
|
1天前
|
监控 安全 Java
Java中的多线程编程:从入门到实践####
本文将深入浅出地探讨Java多线程编程的核心概念、应用场景及实践技巧。不同于传统的摘要形式,本文将以一个简短的代码示例作为开篇,直接展示多线程的魅力,随后再详细解析其背后的原理与实现方式,旨在帮助读者快速理解并掌握Java多线程编程的基本技能。 ```java // 简单的多线程示例:创建两个线程,分别打印不同的消息 public class SimpleMultithreading { public static void main(String[] args) { Thread thread1 = new Thread(() -> System.out.prin
|
5天前
|
Java
JAVA多线程通信:为何wait()与notify()如此重要?
在Java多线程编程中,`wait()` 和 `notify()/notifyAll()` 方法是实现线程间通信的核心机制。它们通过基于锁的方式,使线程在条件不满足时进入休眠状态,并在条件满足时被唤醒,从而确保数据一致性和同步。相比其他通信方式,如忙等待,这些方法更高效灵活。 示例代码展示了如何在生产者-消费者模型中使用这些方法实现线程间的协调和同步。
14 3