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

2.技术选型

3.系统功能

4.数据库

二、系统展示

1.登录页面

2.主页面

3.查询学生信息

4.添加学生信息

5.修改学生信息

三、部分代码

StudentDao

StuDaoImpl

StudentService

StudentServiceImpl

四、其他

1.其他系统实现

1.JavaWeb系统系列实现

2.JavaSwing系统系列实现

2.获取源码

3.运行项目

4.备注

5.支持博主

6.鸡汤


一、系统介绍

======

1.开发环境


开发工具:IDEA2018.2

JDK版本:jdk1.8

Mysql版本:8.0.13

2.技术选型


后端使用Java+Servlet进行开发,前端为Jsp,数据库为Mysql。

3.系统功能


1. 登录系统

2.查询学生信息

3.新增学生信息

4.修改学生信息

5.删除学生信息

4.数据库


/*

Navicat Premium Data Transfer

Source Server : Mysql

Source Server Type : MySQL

Source Server Version : 80013

Source Host : localhost:3306

Source Schema : jsp_servlet_studentinfo

Target Server Type : MySQL

Target Server Version : 80013

File Encoding : 65001

Date: 16/07/2021 21:24:47

*/

SET NAMES utf8mb4;

SET FOREIGN_KEY_CHECKS = 0;


– Table structure for account


DROP TABLE IF EXISTS account;

CREATE TABLE account (

username varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,

password varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,

nickname varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL

) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;


– Records of account


INSERT INTO account VALUES (‘admin’, ‘admin’, ‘管理员’);


– Table structure for stuinfo


DROP TABLE IF EXISTS stuinfo;

CREATE TABLE stuinfo (

Id varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

Name varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

Age int(5) NOT NULL,

Dep varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

Sex varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

Phone varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

Email varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

PRIMARY KEY (Id) USING BTREE

) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;


– Records of stuinfo


INSERT INTO stuinfo VALUES (‘105001’, ‘黄晋江’, 35, ‘数计院’, ‘男’, ‘18050193364’, ‘48577342@qq.com’);

INSERT INTO stuinfo VALUES (‘105002’, ‘叶小白’, 21, ‘数计院’, ‘男’, ‘18056789321’, ‘4793247@qq.com’);

INSERT INTO stuinfo VALUES (‘105003’, ‘林幼玲’, 19, ‘医学院’, ‘女’, ‘15745492821’, ‘4488742@qq.com’);

INSERT INTO stuinfo VALUES (‘105004’, ‘白凌琳’, 20, ‘文学院’, ‘女’, ‘180437289678’, ‘75834538@qq.com’);

INSERT INTO stuinfo VALUES (‘105005’, ‘廖江土’, 22, ‘数计院’, ‘男’, ‘18050400657’, ‘73476432@qq.com’);

INSERT INTO stuinfo VALUES (‘105009’, ‘黄晋江’, 77, ‘数计院’, ‘男’, ‘18050193364’, ‘48577342111@qq.com’);

SET FOREIGN_KEY_CHECKS = 1;

二、系统展示

======

1.登录页面


2.主页面


3.查询学生信息


4.添加学生信息


5.修改学生信息


三、部分代码

=======

StudentDao


package cn.fjnu.edu.dao;

import cn.fjnu.edu.model.Student;

import java.util.List;

public interface StudentDao {

public boolean Create(Student student) throws Exception;

public boolean Update(Student student) throws Exception;

public boolean Delete(Student student) throws Exception;

public boolean findLogin(Student student) throws Exception;

List findAll(String keyWord) throws Exception;

}

StuDaoImpl


package cn.fjnu.edu.daoimpl;

import cn.fjnu.edu.dao.StudentDao;

import cn.fjnu.edu.model.Student;

import cn.fjnu.edu.util.DBUtil;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.List;

public class StuDaoImpl implements StudentDao {

final String strCreate = “insert into stuinfo values(?,?,?,?,?,?,?)”;

final String strDelete = “delete from stuinfo where 1=1”;

final String strUpdate = “update stuinfo set”;

final String strFind = “select * from stuinfo where Name like ? or Dep like ? or Id like ? or Age like ? or Sex like ? or Phone like ? or Email like ?”;

final String strLogin = “select Name from stuinfo where id=? and Phone=?”;

@Override

public boolean Create(Student student) throws Exception {

DBUtil msh = new DBUtil();

Connection conn = msh.getConnection();

PreparedStatement pstmt = conn.prepareStatement(strCreate);

pstmt.setString(1, student.getId());

pstmt.setString(2, student.getName());

pstmt.setInt(3, student.getAge());

pstmt.setString(4, student.getDep());

pstmt.setString(5, student.getSex());

pstmt.setString(6, student.getPhone());

pstmt.setString(7, student.getEmail());

int i = pstmt.executeUpdate();

pstmt.close();

if (i > 0)

return true;

else

return false;

}

@Override

public boolean Update(Student student) throws Exception {

DBUtil msh = new DBUtil();

Connection conn = msh.getConnection();

Statement stmt = conn.createStatement();

String str = strUpdate;

if (!(student.getName().equals(null))) {

str += " Name=‘" + student.getName() + "’ ";

}

if (!(student.getDep().equals(null)))

str += “,Dep='” + student.getDep() + “'”;

if (!(student.getSex().equals(null)))

str += “,Sex='” + student.getSex() + “'”;

if (!(student.getPhone().equals(null)))

str += “,Phone='” + student.getPhone() + “'”;

if (!(student.getEmail().equals(null)))

str += “,Email='” + student.getEmail() + “'”;

if (student.getAge() != 0) {

str += “,Age=” + student.getAge() + “”;

}

str += " where Id=" + student.getId() + “;”;

System.out.println(str);

int i = stmt.executeUpdate(str);

stmt.close();

msh.closeConnection(conn);

if (i > 0)

return true;

else {

System.out.println(i + " errorD");

return false;

}

}

@Override

public boolean Delete(Student student) throws Exception {

DBUtil msh = new DBUtil();

Connection conn = msh.getConnection();

Statement stmt = conn.createStatement();

String str = strDelete;

if (!(“”.equals(student.getId())))

str += " and Id=" + student.getId();

int i = stmt.executeUpdate(str);

stmt.close();

msh.closeConnection(conn);

if (i > 0)

return true;

else

return false;

}

@Override

public boolean findLogin(Student student) throws Exception {

DBUtil msh = new DBUtil();

Connection conn = msh.getConnection();

PreparedStatement pstmt = conn.prepareStatement(strCreate);

boolean flag = false;

try {

pstmt = conn.prepareStatement(strLogin);

pstmt.setString(1, student.getId());

pstmt.setString(2, student.getPhone());

ResultSet rs = pstmt.executeQuery();

if (rs.next()) {

student.setName(rs.getString(1));

flag = true;

}

} catch (Exception e) {

throw e;

} finally {

if (pstmt != null) {

try {

pstmt.close();

} catch (Exception e) {

throw e;

}

}

}

return flag;

}

@Override

public List findAll(String keyWord) throws Exception {

List all = new ArrayList();

DBUtil msh = new DBUtil();

Connection conn = msh.getConnection();

PreparedStatement pstmt = conn.prepareStatement(strFind);

pstmt.setString(1, “%” + keyWord + “%”);

pstmt.setString(2, “%” + keyWord + “%”);

pstmt.setString(3, “%” + keyWord + “%”);

pstmt.setString(4, “%” + keyWord + “%”);

pstmt.setString(5, “%” + keyWord + “%”);

pstmt.setString(6, keyWord);

pstmt.setString(7, keyWord);

ResultSet rs = pstmt.executeQuery();

Student people = null;

while (rs.next()) {

people = new Student();

people.setId(rs.getString(1));

people.setName(rs.getString(2));

people.setAge(rs.getInt(3));

people.setDep(rs.getString(4));

people.setSex(rs.getString(5));

people.setPhone(rs.getString(6));

people.setEmail(rs.getString(7));

all.add(people);

}

pstmt.close();

msh.closeConnection(conn);

return all;

}

}

StudentService


package cn.fjnu.edu.service;

import cn.fjnu.edu.model.Student;

import java.util.List;

public interface StudentService {

public boolean Create(Student student) throws Exception;

public boolean Update(Student student) throws Exception;

public boolean Delete(Student student) throws Exception;

public boolean findLogin(Student student) throws Exception;

List findAll(String keyWord) throws Exception;

}

StudentServiceImpl


package cn.fjnu.edu.serviceimpl;

import cn.fjnu.edu.daoimpl.StuDaoImpl;

import cn.fjnu.edu.model.Student;

import cn.fjnu.edu.service.StudentService;

import java.util.List;

public class StudentServiceImpl implements StudentService {

@Override

public boolean Create(Student student) throws Exception {

StuDaoImpl sdi = new StuDaoImpl();

return sdi.Create(student);

}

@Override

public boolean Update(Student student) throws Exception {

StuDaoImpl sdi = new StuDaoImpl();

boolean s = sdi.Update(student);

return s;

}

@Override

public boolean Delete(Student student) throws Exception {

StuDaoImpl sdi = new StuDaoImpl();

return sdi.Delete(student);

}

@Override

public List findAll(String keyWord) throws Exception {

StuDaoImpl sdi = new StuDaoImpl();

List all = null;

all = sdi.findAll(keyWord);

return all;

}

@Override

public boolean findLogin(Student student) throws Exception {

StuDaoImpl sdi = new StuDaoImpl();

return sdi.findLogin(student);

}

}

四、其他

====

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值