基于Java swing+MySQL实现学生信息管理系统:主要实现JDBC对学生信息进行增删改查,应付一般课设足矣,分享给大家。(由于篇幅原因,代码未全部列出,如有需要加上我个人简介的qq群)
1、 开发环境:jdk7+MySQL5+win7
代码结构:model-dao-view
2、 数据库设计--建库建表语句:
CREATE DATABASE student;
DROP TABLE IF EXISTS `admin`;CREATE TABLE `admin` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, `username` varchar(20) NOT NULL, `password` varchar(20) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;LOCK TABLES `admin` WRITE;INSERT INTO `admin` VALUES (1,'admin','admin','admin');UNLOCK TABLES;DROP TABLE IF EXISTS `student`;CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, `sno` varchar(20) NOT NULL, `department` varchar(20) NOT NULL, `hometown` varchar(20) NOT NULL, `mark` varchar(20) NOT NULL, `email` varchar(20) NOT NULL, `tel` varchar(20) NOT NULL, `sex` varchar(20) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;LOCK TABLES `student` WRITE;INSERT INTO `student` VALUES (18,'张三','001','信息科学技术学院','辽宁','80','zhangsan@163.com','13888888888','男'),(19,'李四','002','理学院','上海','70','lisi@sina.com','13812341234','男'),(20,'王五','003','外国语学院','北京','88','wangwu@126.com','13698765432','女');UNLOCK TABLES;
3、model--管理员、学生
/**
* 项目名:student
* 修改历史:
* 作者: MZ
* 创建时间: 2018年12月4日-上午9:42:48
*/
package com.student.model;
/**
* 模块说明:admin
*
*/
public class Admin {
private int id;
private String name;
private String username;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
/**
* 项目名:student
* 修改历史:
* 作者: MZ
* 创建时间: 2016年1月6日-上午9:42:36
*/
package com.student.model;
/**
* 模块说明: 学生
*
*/
public class Student {
private int id;
private String sno;// 学号
private String name;
private String sex;
private String department;// 院系
private String homeTown;// 籍贯
private String mark;// 学分
private String email;
private String tel;// 联系方式
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getSno() {
return sno;
}
public void setSno(String sno) {
this.sno = sno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getHomeTown() {
return homeTown;
}
public void setHomeTown(String homeTown) {
this.homeTown = homeTown;
}
public String getMark() {
return mark;
}
public void setMark(String mark) {
this.mark = mark;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
}
4、 工具类DBUtil(对jdbc进行封装)
/**
* 项目名:student
* 修改历史:
* 作者: MZ
* 创建时间: 2018年12月4日-上午9:43:21
*/
package com.student.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.student.AppConstants;
/**
* 模块说明:数据库工具类
*
*/
public class DBUtil {
private static DBUtil db;
private Connection conn;
private PreparedStatement ps;
private ResultSet rs;
private DBUtil() {
}
public static DBUtil getDBUtil() {
if (db == null) {
db = new DBUtil();
}
return db;
}
public int executeUpdate(String sql)