First subject of training!

JAVA实训项目:GUI学生信息管理系统功能结构图(百度脑图)

在这里插入图片描述

实训项目之创建数据库与表

第一步,打开Navicat工具创建Mysql数据库在这里插入图片描述
第二步,分别创建student,user,college,status4张表
![在这里插入图片描述](https:/在这里插入图片描述在这里插入图片描述在这里插入图片描述
第三步,在把各表输入数据记录
在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述
第四步,打开IntelliJ IDEA软件创建一个“学生管理系统”项目在这里插入图片描述,在项目里创建这几个文件夹在这里插入图片描述
第五步,开始创建实体类,分别是College,Status,Student,User。
在这里插入图片描述

						**学校实体**

/**

  • 包名:kwt.student.bean
  • 类名:College
  • 描述:学校实体
  • 作者:匡文涛
  • 日期:2019年6月17日
    */
    package kwt.student.bean;

import java.util.Date;

public class College {
/**
* 学校标识符
/
private int id;
/
*
* 学校名称
/
private String name;
/
*
* 校长
/
private String president;
/
*
* 建校时间
/
private Date startTime;
/
*
* 联系电话
/
private String telephone;
/
*
* 电子邮箱
/
private String email;
/
*
* 通信地址
/
private String address;
/
*
* 学校简介
*/
private String profile;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getPresident() {
    return president;
}

public void setPresident(String president) {
    this.president = president;
}

public Date getStartTime() {
    return startTime;
}

public void setStarttime(Date startTime) {
    this.startTime = startTime;
}

public String getTelephone() {
    return telephone;
}

public void setTelephone(String telephone) {
    this.telephone = telephone;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public String getProfile() {
    return profile;
}

public void setProfile(String profile) {
    this.profile = profile;
}

@Override
public String toString() {
    return "College{" +
            "id=" + id +
            ", name='" + name + '\'' +
            ", president='" + president + '\'' +
            ", starttime=" + startTime +
            ", telephone='" + telephone + '\'' +
            ", email='" + email + '\'' +
            ", address='" + address + '\'' +
            ", profile='" + profile + '\'' +
            '}';
}

}

						**状态实体**

/**

  • 包名:kwt.student.bean
  • 类名:Status
  • 描述:状态实体
  • 作者:匡文涛
  • 日期:2019年6月17日
    */
    package kwt.student.bean;

public class Status {
/**
* 标识符
/
private int id;
/
*
* 校名
/
private String college;
/
*
* 版本
/
private String version;
/
*
* 作者
/
private String author;
/
*
* 联系电话
/
private String telephone;
/
*
* 通信地址
/
private String adrress;
/
*
* 电子邮箱
*/
private String emaill;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getCollege() {
    return college;
}

public void setCollege(String college) {
    this.college = college;
}

public String getVersion() {
    return version;
}

public void setVersion(String version) {
    this.version = version;
}

public String getAuthor() {
    return author;
}

public void setAuthor(String author) {
    this.author = author;
}

public String getTelephone() {
    return telephone;
}

public void setTelephone(String telephone) {
    this.telephone = telephone;
}

public String getAdrress() {
    return adrress;
}

public void setAdrress(String adrress) {
    this.adrress = adrress;
}

public String getEmaill() {
    return emaill;
}

public void setEmaill(String emaill) {
    this.emaill = emaill;
}

@Override
public String toString() {
    return "Status{" +
            "id=" + id +
            ", college='" + college + '\'' +
            ", version='" + version + '\'' +
            ", author='" + author + '\'' +
            ", telephone='" + telephone + '\'' +
            ", adrress='" + adrress + '\'' +
            ", emaill='" + emaill + '\'' +
            '}';
}

}

						**学生实体**

/**

  • 包名:kwt.student.bean
  • 类名:Student
  • 描述:学生实体
  • 作者:匡文涛
  • 日期:2019年6月17日
    */
    package kwt.student.bean;

public class Student {
/**
* 学号
/
private String id;
/
*
姓名
/
private String name;
/

性别
/
private String sex;
/

年龄
/
private int age;
/

系部
/
private String departTment;
/

班级
/
private String clazz;
/

*联系电话
*/
private String telephone;

public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

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 int getAge() {
    return age;
}

public void setAge(int age) {
    this.age = age;
}

public String getDepartTment() {
    return departTment;
}

public void setDepartTment(String departTment) {
    this.departTment = departTment;
}

public String getClazz() {
    return clazz;
}

public void setClazz(String clazz) {
    this.clazz = clazz;
}

public String getTelephone() {
    return telephone;
}

public void setTelephone(String telephone) {
    this.telephone = telephone;
}
@Override
public String toString() {
    return "Student{" +
            "id='" + id + '\'' +
            ", name='" + name + '\'' +
            ", sex='" + sex + '\'' +
            ", age=" + age +
            ", departtment='" + departTment + '\'' +
            ", clazz='" + clazz + '\'' +
            ", telephone='" + telephone + '\'' +
            '}';
}

}

						**用户实体**

/**

  • 包名:kwt.student.bean
  • 类名:User
  • 描述:用户实体
  • 作者:匡文涛
  • 日期:2019年6月17日
    */
    package kwt.student.bean;

import java.util.Date;

public class User {
/**
* 用户标识符
/
private int id;
/
*
用户名
/
private String username;
/

密码
/
private String password;
/

*联系电话
*/
private String telephone;

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;
}

public String getTelephone() {
    return telephone;
}

public void setTelephone(String telephone) {
    this.telephone = telephone;
}

public Date getRegisterTime() {
    return registerTime;
}

public void setRegisterTime(Date registerTime) {
    this.registerTime = registerTime;
}

/**
 *注册时间
 */
private Date registerTime;

@Override
public String toString() {
    return "User{" +
            "id=" + id +
            ", username='" + username + '\'' +
            ", password='" + password + '\'' +
            ", telephone='" + telephone + '\'' +
            ", registerTime=" + registerTime +
            '}';
}

}

第六步,实施数据库连接管理

/**

  • 包名:kwt.student.dbutil
  • 类名:ConnectionManager
  • 描述:数据库连接管理类
  • 作者:匡文涛
  • 日期:2019年6月17日
    */
    package kwt.student.dbutil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.swing.JOptionPane;

public class ConnectionManager {
/**
* 数据库驱动程序
/
private static final String DRIVER = “com.mysql.jdbc.Driver”;
/
*
* 数据库统一资源标识符
/
private static final String URL = “jdbc:mysql://localhost:3306/student”;
/
*
* 数据库用户名
/
private static final String USERNAME = “root”;
/
*
* 数据库密码
*/
private static final String PASSWORD = “1”;

/**
 * 私有化构造方法,拒绝实例化
 */
private ConnectionManager() {
}

/**
 * 获得数据库连接
 *
 * @return 数据库连接对象
 */
public static Connection getConnection() {
    //定义数据库连接
    Connection conn = null;
    try {
        //安装数据库驱动程序
        Class.forName(DRIVER);
        //获得数据库连接
        conn = DriverManager.getConnection(URL
                + "?useUnicode=true&charcterEncoding=UTF8", USERNAME, PASSWORD);
    }catch (ClassNotFoundException e) { e.printStackTrace();
    }catch (SQLException e){
        e.printStackTrace();
    }
    //返回数据库连接
    return conn;
}

/**
 * 关闭数据库连接
 * @param conn
 */
public static void closeConnection(Connection conn){
    //判断数据库连接是否为空
    if(conn !=null){
        //判断数据库连接是否关闭
        try{
            if (!conn.isClosed()){
                //关闭数据库连接
                conn.close();
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}

/**
 * 测试数据库连接是否成功
 * @param args
 */
public static void main(String[] args){
    //获得数据库连接
    Connection conn = getConnection();
    //判断是否连接成功
    if (conn != null){
        JOptionPane.showMessageDialog(null,"恭喜,数据库连接成功!");
    } else {
        JOptionPane.showMessageDialog(null,"遗憾,数据库连接失败!");
    }

    //关闭数据库连接
    closeConnection(conn);
}

}
运行后会显示连接成功
在这里插入图片描述
第七步,创建Dao文件并编写数据访问接口

										CollegeDao

/**

  • 包名:kwt.student.dao
  • 类名:CollegeDao
  • 描述:学校数据访问接口
  • 作者:匡文涛
  • 日期:2019年6月17日
    */
    package kwt.student.dao;

import kwt.student.bean.College;

public interface CollegeDao {
College findById(int id);
int update(College college);
}

										StatusDao

/**

  • 包名:kwt.student.dao
  • 类名:StatusDao
  • 描述:状态数据访问接口
  • 作者:匡文涛
  • 日期:2019年6月17日
    */
    package kwt.student.dao;

import kwt.student.bean.Status;

public interface StatusDao {
Status findById(int id);
int update(Status status);
}

									StudentDao

/**

  • 包名:kwt.student.dao
  • 类名:StudentDao
  • 描述:学生数据访问接口
  • 作者:匡文涛
  • 日期:2019年6月17日
    */
    package kwt.student.dao;

import kwt.student.bean.Student;

import java.util.List;
import java.util.Vector;

public interface StudentDao {
int insert(Student student);
int deleteById(String id);
int deleteByClass(String clazz);
int deleteByDepartment(String department);
int update(Student student);
Student findById(String id);
List findByName(String name);
List findByClass(String clazz);
List findByDepartment(String department);
List findAll();
Vector findRowsBySex();
Vector findRosByClass();
Vector findRowsByDepartment();

}

										UserDao

/**

  • 包名:kwt.student.dao
  • 类名:UserDao
  • 描述:用户数据访问接口
  • 作者:匡文涛
  • 日期:2019年6月17日
    */
    package kwt.student.dao;

import kwt.student.bean.User;

import java.util.List;

public interface UserDao {
int insert(User user);
int deleteById(int id);
int update(User user);
User findById(int id);
List findAll();
User login(String username,String password);
}

第八步,创建Impl文件实现数据访问接口实现类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值