java课程设计(学生信息管理系统设计)+数据库

🔍 🔎 本期带领大家一起来学习java课程设计(学生信息管理系统设计)+数据库的实现思路 🔍 🔎

题目要求+数据库🌍

学生信息包括:学号,姓名,年龄,性别,出生年月,地址,电话,E-mail等。试设计学生信息管理系统,使之能提供以下功能:
1、系统以菜单方式工作
2、学生信息录入功能--输入
3、学生信息浏览功能--输出
4、学生信息查询功能--算法
按学号查询
按姓名查询
5、学生信息的删除与修改(可选项)

在这里插入图片描述
在这里插入图片描述

一 、环境搭建🌍

在idea创建一个工程文件,在工程文件下创建一个model模块,在model模块下创建一个classSystem包,然后再存放对应的类,如下图所示
在这里插入图片描述
需要注意是因为连接了数据库,所以需要导入相应的jar包

二 、功能实现 🌎 🌍

1.学生信息类的创建✅

首先实现这个学生信息管理系统,我们需要先创建一个学生信息类
,包括学生的学号,姓名,年龄,地址,电话,邮箱,出生日期,具体代码如下✈️ 🛫 🛬

package classSystem;


public class Student {
    private int stuId;
    private String name;
    private int age;

    private String sex;
    private String birth;

    private String address;
    private String tel;
    private String Email;


    public Student() {
    }

    public Student(int stuId, String name, int age, String sex, String birth, String address, String tel, String email) {
        this.stuId = stuId;
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.birth = birth;
        this.address = address;
        this.tel = tel;
        Email = email;
    }

    public int getStuId() {
        return stuId;
    }

    public void setStuId(int stuId) {
        this.stuId = stuId;
    }

    public String getName() {
        return name;
    }

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

    public int getAge() {
        return age;
    }

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

    public String getAddress() {
        return address;
    }

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

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getBirth() {
        return birth;
    }

    public void setBirth(String birth) {
        this.birth = birth;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getEmail() {
        return Email;
    }

    public void setEmail(String email) {
        Email = email;
    }
}


2.学生信息的添加功能✅✅

🔍 🔎因为这个学生信息管理系统的java程序是连接了数据库,所以我们在录入我们的信息的时候,需要讲我们所录入的学生信息存放到数据库当中,所以我们需要运用到sql语句
去添加我们所录入的信息,做到了随时随地可以查询,更好地管理我们的学生信息🔍 🔎

public static void addStu(ArrayList<Student> stu) throws AWTException {
        while (true) {
            Extents.clearConsole();
            System.out.println(">首界面>功能界面>添加学生信息\n\n");
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入学生学号(例:2022): ");
            int stuId=sc.nextInt();
            System.out.print("请输入学生姓名(例:张三): ");
            String name = sc.next();
            System.out.print("请输入学生年龄(例:18): ");
            int age = sc.nextInt();
            System.out.print("请输入学生性别(例:男): ");
            String sex =sc.next();
            System.out.print("请输入学生出生日期(例:2004-6-1): ");
            String birth =sc.next();
            System.out.print("请输入学生电话(例:123456): ");
            String tel=sc.next();
            System.out.print("请输入学生email(例:123456@qq.com): ");
            String emial =sc.next();
            System.out.print("请输入学生地址(例:深圳): ");
            String address = sc.next();

            System.out.println("\n\n-----------------------------------------------------");
            System.out.println( "\t\t学号: "+stuId+"\t\t姓名: " + name + "\t\t年龄: " + age + "\t\t地址: " + address
            +"\t\t性别: " +sex+"\t\t出生日期: " +birth+"\t\t地址: " +address+"\t\t电话: " +tel+"\t\t邮箱: " +emial);
            System.out.print("\n\n是否添加该学生信息? [Yes(1) / No(0)] :");
            Extents.isAdd(stu, sc, stuId,sex,birth,tel,emial, name, age, address);
            System.out.println("\n\n\n>首界面>功能界面>添加学生信息\n");
            System.out.println("\t                继续添加                   请输入1               ");
            System.out.println();
            System.out.println("\t                返回上级                   请输入0               ");
            System.out.println("\t ---------------------------------------------------------------");
            System.out.print("\n请输入您的选择:");
            while (true) {
                int choose = sc.nextInt();
                if (choose == 1) {
                    break;
                } else if (choose == 0) {
                    Extents.clearConsole();
                    return;
                } else {
                    System.out.print("看清选项! 再给你一次机会: ");
                }
            }
        }
    }

public static void isAdd(ArrayList<Student> stu, Scanner sc,int stuId ,String sex,String birth,String tel,String email, String name, int age, String address) throws AWTException {
        while (true) {
            int is = sc.nextInt();
            if (is == 0) {
                Extents.clearConsole();
                System.out.println("取消成功!");
                break;
            } else if (is == 1) {
                /*Student s = new Student(stuId,name, age,sex,birth, address,tel,email);
                stu.add(s);*/
                Connection connection =null;

                String sql ="insert into Student values(?,?,?,?,?,?,?,?)";
                PreparedStatement preparedStatement=null;
                try {

                    connection  = jdbcUtiles.getConnection();
                    preparedStatement = connection.prepareStatement(sql);

                   preparedStatement.setInt(1,stuId);
                   preparedStatement.setString(2,name);
                   preparedStatement.setInt(3,age);
                   preparedStatement.setString(4,sex);
                   preparedStatement.setString(5,address);
                   preparedStatement.setString(6,birth);
                   preparedStatement.setString(7,tel);
                   preparedStatement.setString(8,email);

                    //执行
                    preparedStatement.executeUpdate();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }finally {
                    jdbcUtiles.close(null,preparedStatement,connection);
                }


                stuId += 1;
                Extents.clearConsole();
                System.out.println("添加信息成功!\n\n");
                FunctionalBlock.showStu(stu);
                break;
            }
            System.out.print("\n输入错误!请重新输入:");
        }
    }

相信大家看到这里会有点迷惑,那么现在我来梳理一下增加信息代码块的实现逻辑
首先我们先在FunctionalBlock当中的addStudan当中录入我们的信息🔑 🔑
然后再调用我们Extens当中的isAdd判断是否录入我们的信息
如果录入信息的话,使用sql语句进行与数据库的连接,并且将信息录入到数据库当中
并且会查询数据库当中的信息🔍 🔎
如果不录入信息的话,那么就取消录入

增加学生信息效果图如下
在这里插入图片描述
在这里插入图片描述

3.学生信息的删除功能✅✅✅

学生信息的删除功能的实现,先调用FunctionalBlock
当中的showStu的方法展示全部学生的信息💡💡
再选择需要删除的学生信息💡💡
同样先要判断所输入的学号是=是否存在,用到了Extents当中的getFlag的方法
如果不存在,则返回-1,存在的话则进行删除操作
同样用到了sql语句与数据库当中的学生信息进行了交互🔑

public static void deleteStu(ArrayList<Student> stu) throws AWTException {
        Scanner sc = new Scanner(System.in);
        showStu(stu);
        while (true) {
            System.out.print("\n请输入要删除的学生学号:");
            int sid = sc.nextInt();
            sc.nextLine();
            int flag = Extents.getFlag(stu, sid);
            if (flag == -1) {
                System.out.print("\n该学号不存在,请重新输入\n");
            } else {
                System.out.print("\n是否删除学号为:" + sid + " 的学生信息? [Yes(1) / No(0)] :");
                Extents.isDlete(stu, sc, flag);
                System.out.println("\n\n\n>首界面>功能界面>删除学生信息\n");
                System.out.println("\t                继续删除                   请输入1                ");
                System.out.println();
                System.out.println("\t                返回上级                   请输入0                ");
                System.out.println("\t ----------------------------------------------------------------");
                System.out.print("\n请输入您的选择: ");
                while (true) {
                    int choose = sc.nextInt();
                    if (choose == 1) {
                        break;
                    } else if (choose == 0) {
                        Extents.clearConsole();
                        return;
                    } else {
                        System.out.print("看清选项! 再给你一次机会: ");
                    }
                }
            }
        }
    }

删除学生信息效果图如下

在这里插入图片描述

4.学生信息的修改功能 ✅✅✅✅

修改学生信息的功能呢,和上面删除学生信息 功能的实现类似,我们同样来看看如何实现的
学生信息的修改功能的实现,先调用FunctionalBlock当中的showStu的方法展示全部学生的信息
再选择需要修改的学生学号⌛️ ⏳⌛️ ⏳
同样先要判断所输入的学号是=是否存在,用到了Extents当中的getFlag的方法
如果不存在,则返回-1,存在的话则进行修改操作
再然后输入修改之后的学生信息💡💡
同样用到了sql语句与数据库当中的学生信息进行了交互

 public static void updateStu(ArrayList<Student> stu) throws AWTException {
        Scanner sc = new Scanner(System.in);
        while (true) {
            showStu(stu);
            System.out.print("\n\n请输入要修改信息的学生学号:");
            int sidUpdate = sc.nextInt();
            int flag = Extents.getFlag(stu, sidUpdate);
            Extents.clearConsole();
            if (flag == -1) {
                System.out.print("该学号不存在,请重新输入\n\n\n ");
            } else {
                System.out.println(">首界面>功能界面>修改学生信息\n\n");
                System.out.print("请输入学生学号(例:2022: ");
                int id=sc.nextInt();
                System.out.print("请输入学生姓名(例:张三): ");
                String name = sc.next();
                System.out.print("请输入学生年龄(例:18): ");
                int age = sc.nextInt();
                System.out.print("请输入学生性别(例:男): ");
                String sex =sc.next();
                System.out.print("请输入学生出生日期(例:2004-6-1): ");
                String birth =sc.next();
                System.out.print("请输入学生电话(例:123456): ");
                String tel=sc.next();
                System.out.print("请输入学生email(例:123456@qq.com): ");
                String emial =sc.next();
                System.out.print("请输入学生地址(例:深圳): ");
                String address = sc.next();
                Extents.clearConsole();
                Extents.getFlag(stu, sidUpdate);


                Connection connection =null;
                String sql ="update Student set stuId=? ,name=?,age=?,sex=?,adress=?,birth=?,tel=?,Email=?where stuId=?";
                PreparedStatement preparedStatement=null;
                try {
                    connection  = jdbcUtiles.getConnection();
                    preparedStatement = connection.prepareStatement(sql);
                    preparedStatement.setInt(1,id);
                    preparedStatement.setString(2,name);
                    preparedStatement.setInt(3,age);
                    preparedStatement.setString(4,sex);
                    preparedStatement.setString(5,address);
                    preparedStatement.setString(6,birth);
                    preparedStatement.setString(7,tel);
                    preparedStatement.setString(8,emial);
                    preparedStatement.setInt(9,flag);

                    //执行
                    preparedStatement.executeUpdate();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }finally {
                    jdbcUtiles.close(null,preparedStatement,connection);
                }




                System.out.println(">首界面>功能界面>修改学生信息");
                System.out.println("\n\n------------------------------------------------------------------");

                System.out.println("修改后——>\n");
                System.out.println( "\t\t姓名: " + name + "\t\t年龄: " + age + "\t\t地址: " + address
                        +"\t\t性别: " +sex+"\t\t出生日期: " +birth+"\t\t地址: " +address+"\t\t电话: " +tel+"\t\t邮箱: " +emial);
                System.out.print("\n\n是否修改该学生信息? [Yes(1) / No(0)] :");
                Extents.isUpdata(stu, sc, sidUpdate, flag,sex,birth,tel,emial, name, age, address);
                System.out.println("\n\n\n>首界面>功能界面>修改学生信息\n");
                System.out.println("\t                继续修改                   请输入1              ");
                System.out.println();
                System.out.println("\t                返回上级                   请输入0              ");
                System.out.println("\t --------------------------------------------------------------");
                System.out.print("\n请输入您的选择:");
                while (true) {
                    int choose = sc.nextInt();
                    if (choose == 1) {
                        Extents.clearConsole();
                        break;
                    } else if (choose == 0) {
                        Extents.clearConsole();
                        return;
                    } else {
                        System.out.print("看清选项! 再给你一次机会: ");
                    }
                }
            }
        }
    }

修改学生信息效果图如下
在这里插入图片描述

5.学生信息的查看功能✅✅✅✅✅

由于查看学生信息的功能在前面三个功能当中都有调用⌛️ ⏳⌛️ ⏳
所以我们为了使得代码更加简洁,将查询学生信息的功能封装起来了
避免了代码的冗余
同样我们来看看到底是如何实现的
因为我们的程序是连接了数据库,所以我们需要查询学生的信息的时候⌛️ ⏳⌛️ ⏳
需要用到查询的sql语句进行查询,同我们的数据库进行交互

 public static void showStu(ArrayList<Student> stu) {

        System.out.println("1.按学号查询");
        System.out.println("2.按姓名查询");
        System.out.println("3.查询全部 ");
        Scanner sc =new Scanner(System.in);
        int input=sc.nextInt();
        if(input==1){
            System.out.print("输入需要查询的学生学号:");
            int stuid=sc.nextInt();

            Connection connection =null;
            String sql="select stuId,name,age,sex,adress,birth,tel,Email from Student where stuId=?";
            PreparedStatement preparedStatement=null;
            ResultSet set=null;
            try {
                connection  = jdbcUtiles.getConnection();
                preparedStatement = connection.prepareStatement(sql);

                preparedStatement.setInt(1,stuid);
                //执行
                set = preparedStatement.executeQuery();

                while(set.next()){
                    int id=set.getInt("stuId");
                    String name=set.getString("name");
                    int age =set.getInt("age");
                    String sex =set.getString("sex");
                    String address=set.getString("adress");
                    String birth=set.getString("birth");
                    String tel=set.getString("tel");
                    String email=set.getString("Email");

                    System.out.println("\t\t" + id + " \t\t\t" + name
                            + " \t\t\t" + age + " \t\t\t" + sex +" \t\t\t" + address +
                            " \t\t\t" + birth+ " \t\t\t" + tel +" \t\t\t" + email +
                            "  \t\t\t"  + "\n");
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }finally {
                jdbcUtiles.close(set,preparedStatement,connection);
            }

        } else if (input==2) {


            System.out.print("输入需要查询的学生名字:");
            String stuname=sc.next();

            Connection connection =null;
            String sql="select stuId,name,age,sex,adress,birth,tel,Email from Student where name=?";
            PreparedStatement preparedStatement=null;
            ResultSet set=null;
            try {
                connection  = jdbcUtiles.getConnection();
                preparedStatement = connection.prepareStatement(sql);

                preparedStatement.setString(1,stuname);
                //执行
                set = preparedStatement.executeQuery();

                while(set.next()){
                    int id=set.getInt("stuId");
                    String name=set.getString("name");
                    int age =set.getInt("age");
                    String sex =set.getString("sex");
                    String address=set.getString("adress");
                    String birth=set.getString("birth");
                    String tel=set.getString("tel");
                    String email=set.getString("Email");

                    System.out.println("\t\t" + id + " \t\t\t" + name
                            + " \t\t\t" + age + " \t\t\t" + sex +" \t\t\t" + address +
                            " \t\t\t" + birth+ " \t\t\t" + tel +" \t\t\t" + email +
                            "  \t\t\t"  + "\n");
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }finally {
                jdbcUtiles.close(set,preparedStatement,connection);
            }
        }else{
            System.out.println(">学生信息显示\n");

            System.out.println("\t --------------------------------------------------------------------------------------------------------");
            System.out.println("\t   学号\t\t" + "   姓名\t\t" + " \t年龄\t" + "\t\t性别" + " \t\t\t地址"+
                    " \t\t\t出生日期"+" \t\t\t电话"+" \t\t\t邮箱" );
            System.out.println("\t  ------------------------------------------------------------------------------------------------------");

            Connection connection =null;
            String sql="select * from Student";
            PreparedStatement preparedStatement=null;
            ResultSet set=null;
            try {
                connection  = jdbcUtiles.getConnection();
                preparedStatement = connection.prepareStatement(sql);

                //执行
                set = preparedStatement.executeQuery();

                while(set.next()){
                    int id=set.getInt("stuId");
                    String name=set.getString("name");
                    int age =set.getInt("age");
                    String sex =set.getString("sex");
                    String address=set.getString("adress");
                    String birth=set.getString("birth");
                    String tel=set.getString("tel");
                    String email=set.getString("Email");

                    System.out.println("\t\t" + id + " \t\t\t" + name
                            + " \t\t\t" + age + " \t\t\t" + sex +" \t\t\t" + address +
                            " \t\t\t" + birth+ " \t\t\t" + tel +" \t\t\t" + email +
                            "  \t\t\t"  + "\n");
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }finally {
                jdbcUtiles.close(set,preparedStatement,connection);
            }
            System.out.println("\t  ------------------------------------" +
                    "------------------------------------------------------------------");
        }
        }

查询学生信息效果图如下
在这里插入图片描述

三、主类的调用🌍 🌎 🌏

1、 登录界面🛸

首先出现登陆的界面,我们需要输入我们的用户名和密码,然后判断是否正确
正确的话则执行下一步操作🍗 🍖 🦴


 public static void interFace() throws AWTException {
        System.out.println(">首界面\n");
        System.out.println("\t*****************************************************************");
        System.out.println("\t                           首界面                              ");
        System.out.println("\t ---------------------------------------------------------------");
        System.out.println("\t                开始登录                   请输入1               ");
        System.out.println("\t ---------------------------------------------------------------");
        System.out.println("\t                退出                      请输入0               ");
        System.out.println("\t*****************************************************************");
        Scanner sc = new Scanner(System.in);
        System.out.print("\n请输入您的选择: ");
        while (true) {
            int choose = sc.nextInt();
            if (choose == 1) {

                register();
                break;
            } else if (choose == 0) {
                System.out.println("退出成功!");
                System.exit(0);
            } else {
                System.out.print("看清选项! 再给你一次机会:");
            }
        }
    }
  public static void register() throws AWTException {
        for (int i = COUNT; i >= 0; i--) {
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入您的用户名: ");
            String loginSid = sc.nextLine();
            System.out.print("请输入您的密码: ");
            String loginPassWd = sc.nextLine();
            if (loginSid.equals(MYSID) && loginPassWd.equals(MYPASSWD)) {
                Extents.clearConsole();
                System.out.println("欢迎登录! 用户:" + MYSID + "\n\n");
                menu();
                break;
            } else {
                if (i == 0) {
                    System.out.println("你是不是傻!");
                    System.exit(0);
                }
                System.out.println("错了错了, 你还有 " + i + " 次机会");
            }
        }
    }

2、 界面搭建🛸🛸

 public static void menu() throws AWTException {
        ArrayList<Student> stu = new ArrayList<>();
        while (true) {
            System.out.println(">首界面>功能界面\n");
            System.out.println("\t*****************************************************************");
            System.out.println("\t                      欢迎来到学生管理系统!                      ");
            System.out.println("\t ---------------------------------------------------------------");
            System.out.println("\t                         1.添加学生信息                          ");
            System.out.println("\t ---------------------------------------------------------------");
            System.out.println("\t                         2.删除学生信息                          ");
            System.out.println("\t ---------------------------------------------------------------");
            System.out.println("\t                         3.修改学生信息                          ");
            System.out.println("\t ---------------------------------------------------------------");
            System.out.println("\t                         4.查看学生信息                          ");
            System.out.println("\t ---------------------------------------------------------------");
            System.out.println("\t         q:返回上级菜单                  p:退出管理系统          ");
            System.out.println("\t******************************************************************");
            Scanner sc = new Scanner(System.in);
            System.out.print("\n请输入您的选择:");
            String choose = sc.nextLine();
            switch (choose) {
                case "1":
                    FunctionalBlock.addStu(stu);
                    break;
                case "2":
                    Extents.clearConsole();
                    FunctionalBlock.deleteStu(stu);
                    break;
                case "3":
                    Extents.clearConsole();
                    FunctionalBlock.updateStu(stu);
                    break;
                case "4":
                    Extents.clearConsole();
                    FunctionalBlock.showStu(stu);
                    Extents.isShow(sc);
                    break;
                case "q":
                    Extents.clearConsole();
                    interFace();
                    return;
                case "p":
                    System.out.println("退出成功!");
                    System.exit(0);
                default:
                    Extents.clearConsole();
                    System.out.println("这都错!看清选项再选\n\n\n");
                    break;
            }
        }
    }

四、 Extents的相关善后操作🌎 🌏 🌎 🌏

Extents是完成相关的善后操作,是对FunctionalBlock里面功能实现的相关善后的操作
目的是为了使得更加程序逻辑清晰🍗 🍖 🦴

package classSystem;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Scanner;


public class Extents {


    public static void isAdd(ArrayList<Student> stu, Scanner sc,int stuId ,String sex,String birth,String tel,String email, String name, int age, String address) throws AWTException {
        while (true) {
            int is = sc.nextInt();
            if (is == 0) {
                Extents.clearConsole();
                System.out.println("取消成功!");
                break;
            } else if (is == 1) {
                /*Student s = new Student(stuId,name, age,sex,birth, address,tel,email);
                stu.add(s);*/
                Connection connection =null;

                String sql ="insert into Student values(?,?,?,?,?,?,?,?)";
                PreparedStatement preparedStatement=null;
                try {

                    connection  = jdbcUtiles.getConnection();
                    preparedStatement = connection.prepareStatement(sql);

                   preparedStatement.setInt(1,stuId);
                   preparedStatement.setString(2,name);
                   preparedStatement.setInt(3,age);
                   preparedStatement.setString(4,sex);
                   preparedStatement.setString(5,address);
                   preparedStatement.setString(6,birth);
                   preparedStatement.setString(7,tel);
                   preparedStatement.setString(8,email);

                    //执行
                    preparedStatement.executeUpdate();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }finally {
                    jdbcUtiles.close(null,preparedStatement,connection);
                }


                stuId += 1;
                Extents.clearConsole();
                System.out.println("添加信息成功!\n\n");
                FunctionalBlock.showStu(stu);
                break;
            }
            System.out.print("\n输入错误!请重新输入:");
        }
    }

    public static void isDlete(ArrayList<Student> stu, Scanner sc, int flag) throws AWTException {
        while (true) {
            int is = sc.nextInt();
            if (is == 0) {
                Extents.clearConsole();
                System.out.println("取消成功!");
                break;
            } else if (is == 1) {

                Connection connection =null;
                String sql ="delete from Student  where stuId=?";

                PreparedStatement preparedStatement=null;
                try {

                    connection  = jdbcUtiles.getConnection();
                    preparedStatement = connection.prepareStatement(sql);
                    preparedStatement.setInt(1,flag);

                    //执行
                    preparedStatement.executeUpdate();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }finally {
                    jdbcUtiles.close(null,preparedStatement,connection);
                }



                Extents.clearConsole();
                System.out.println("删除学生信息成功!\n\n");
                FunctionalBlock.showStu(stu);
                break;
            }
            System.out.print("\n输入错误!请重新输入:");
        }
    }

    public static void isUpdata(ArrayList<Student> stu, Scanner sc, int sidUpdate, int flag, String sex,String birth,String tel,String email, String name, int age, String address) throws AWTException {
        while (true) {
            int is = sc.nextInt();
            if (is == 0) {
                Extents.clearConsole();
                System.out.println("取消成功!");
                break;
            } else if (is == 1) {
                Student newStu = new Student(sidUpdate, name,age,sex,birth,address, tel,email);
                Extents.clearConsole();
                System.out.println("修改学生信息成功!\n\n");
                FunctionalBlock.showStu(stu);
                break;
            }
            System.out.print("\n输入错误!请重新输入:");
        }
    }

    public static void isShow(Scanner sc) throws AWTException {
        System.out.println("\n\n\n>首界面>功能界面>查看学生信息\n\n");
        System.out.println("\t              返回上级                     请输入0           ");
        System.out.println("\t ---------------------------------------------------------------");
        System.out.print("\n请输入您的选择: ");
        while (true) {
            int choose1 = sc.nextInt();
            if (choose1 == 0) {
                Extents.clearConsole();
                break;
            } else {
                System.out.print("看清选项! 再给你一次机会: ");
            }
        }
    }

    public static int getFlag(ArrayList<Student> stu, int sid) {

        Connection connection =null;
        String sql="select * from Student";
        PreparedStatement preparedStatement=null;
        ResultSet set=null;
        try {
            connection  = jdbcUtiles.getConnection();
            preparedStatement = connection.prepareStatement(sql);

            //执行
            set = preparedStatement.executeQuery();

            while(set.next()){

                int id  =set.getInt("stuId");
                if(sid==id){
                    return id;
                }
            }
            return -1;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            jdbcUtiles.close(set,preparedStatement,connection);
        }




    }

    public static void clearConsole() throws AWTException {
        Robot r = new Robot();
        // 按下Ctrl键
        r.keyPress(KeyEvent.VK_CONTROL);
        // 按下R键
        r.keyPress(KeyEvent.VK_R);
        // 释放R键
        r.keyRelease(KeyEvent.VK_R);
        // 释放Ctrl键
        r.keyRelease(KeyEvent.VK_CONTROL);
        r.delay(50);
    }
}

五、 数据库的连接🌍 🌎🌏 🌍 🌎 🌏

毕竟我们的这个项目是要连接到数据库当中的
🚴🏼‍♂️ 🚵🏼‍♀️所以我们需要手动操作完成数据库连接的相关代码 🚴🏼‍♂️ 🚵🏼‍♀️

package classSystem;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class jdbcUtiles {

    //工具类,连接mysql的连接和关闭

    private static String user;
    private static String password;
    private static String url;
    private static String driver;

    static {
        Properties properties =new Properties();
        try {
            properties.load(new FileInputStream("src\\mysql.properties"));

            //读取相关属性
            user=properties.getProperty("uesr");
            password =properties.getProperty("password");
            url=properties.getProperty("url");
            driver = properties.getProperty("driver");


        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
    //连接数据库

    public static Connection getConnection(){

        try {
            return DriverManager.getConnection(url,user,password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }


    //关闭相关资源
    public static void close(ResultSet set, PreparedStatement preparedStatement,Connection connection){

        try {
            if(set!=null){
                set.close();
            }
            if(preparedStatement!=null){
                preparedStatement.close();
            }
            if(connection!=null){
                connection.close();
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }

}

在这里插入图片描述

六 、感谢与交流🌍 🌎 🌏 🌍 🌎 🌏

🌹🌹🌹如果大家通过本篇博客收获了,对通过ava实现学生课程管理系统(数据库)
有了更好的了解的话
那么希望支持一下哦如果还有不明白的,疑惑的话,或者什么比较好的建议的话,可以发到评论区,
我们一起解决,共同进步 ❗️❗️❗️
最后谢谢大家❗️❗️❗️💯💯💯

  • 69
    点赞
  • 447
    收藏
    觉得还不错? 一键收藏
  • 35
    评论
第1章 记忆测试软件1.1. 设计内容1.2. 设计要求1.3. 总体设计1.4. 具体设计1.4.1. 运行效果与程序发布1.4.2. 主类Memory1.4.3. 方块 Block1.4.4. 记忆测试板MemoryTestPane1.4.5. 显示成绩 ShowRecord1.4.6. 记录成绩 Record1.4.7. 随机排列图标 RandomSetIcon1.4.8. 测试者 People1.5. 课程设计作业第2章 计算器2.1. 设计内容2.2. 设计要求2.3. 总体设计2.4. 具体设计2.4.1. 运行效果与程序发布2.4.2. 主类 ComputerPad2.4.3. 数值按钮NumberButton2.4.4. 运算符号按钮OperationButton2.5. 课程设计作业第3章 HANNOI-塔3.1. 设计内容3.2. 设计要求3.3. 总体设计3.4. 具体设计3.4.1. 运行效果与程序发布3.4.2. 主类 Tower3.4.3. Hannoi-塔 HannoiTower3.4.4. 塔点 TowerPoint3.4.5. 盘子 Disk3.5. 课程设计作业第4章 JPEG图象生成器4.1. 设计内容4.2. 设计要求4.3. 总体设计4.4. 具体设计4.4.1. 运行效果与程序发布4.4.2. 主类 MakeJPEG.java4.5. 课程设计作业第5章 标准化考试系统 (单机版)5.1. 设计内容5.2. 设计要求5.3. 总体设计5.4. 具体设计5.4.1. 运行效果与程序发布5.4.2. 主类EnglishTest5.4.3. 考试区域TestArea5.4.4. 读取试题 ReadTestquestion5.5. 课程设计作业第6章 标准化考试系统 (C/S网络版)6.1. 设计内容6.2. 设计要求6.3. 总体设计6.4. 具体设计6.4.1. 运行效果与程序发布6.4.2. 客户端主类Client6.4.3. 客户端选择试题界面ChoiceFile6.4.4. 客户端考试界面ClientTestArea6.4.5. 服务器端主类Server6.4.6. 服务器端读取试题 ReadTestquestion6.5. 课程设计作业第7章 标准化考试系统 (B/S网络版)7.1. 设计内容7.2. 设计要求7.3. 总体设计7.4. 具体设计7.4.1. 运行效果与程序发布7.4.2. 客户端主类ClientBS7.4.3. 客户端选择试题界面ChoiceFile7.4.4. 客户端考试界面ClientTestArea7.4.5. 服务器端主类Server7.4.6. 服务器端读取试题 ReadTestquestion7.5. 课程设计作业第8章 日历记事本8.1. 设计内容8.2. 设计要求8.3. 总体设计8.4. 具体设计8.4.1. 运行效果与程序发布8.4.2. 主类CalendarPad8.4.3. 记事本NotePad8.4.4. 年Year8.4.5. 月Month8.5. 课程设计作业18.6. 课程设计作业2第9章 学籍管理系统9.1. 设计内容9.2. 设计要求9.3. 总体设计9.4. 具体设计9.4.1. 运行效果与程序发布9.4.2. 主类StudentManager9.4.3. 录入界面StudentSituation9.4.4. 查询界面Inquest9.4.5. 修改界面ModifySituation9.4.6. 删除界面Delete9.4.7. 学生对象Student9.5. 课程设计作业第10章 图书查询系统 (B/S网络版)10.1. 设计内容10.2. 设计要求10.3. 总体设计10.4. 具体设计10.4.1. 运行效果与程序发布10.4.2. 客户端主类DatabaseClient10.4.3. 服务器端主类DatabaseServer10.5. 课程设计作业第11章 中国象棋打谱软件11.1. 设计内容11.2. 设计要求11.3. 总体设计11.4. 具体设计11.4.1. 运行效果与程序发布11.4.2. 主类 Chess11.4.3. 对弈棋盘ChessBoard11.4.4. 棋子ChessPiece11.4.5. 棋点 ChessPoint11.4.6. 走棋法则Rule11.4.7. 步骤MoveStep11.4.8. 记录棋谱MakeChessManual11.4.9. 棋谱演示Demon11.5. 课程设计作业111.6. 课程设计作业2第12章 魔板游戏12.1. 设计内容12.2. 设计要求12.3. 总体设计12.4. 具体设计12.4.1. 运行效果与程序发布12.4.2. 主类PuzzleFrame12.4.3. 魔板PuzzlePad12.4.4. 魔板中的点SquarePoint12.5. 课程设计作业第13章 挖雷游戏13.1. 设计内容13.2. 设计要求13.3. 总体设计13.4. 具体设计13.4.1. 运行效果与程序发布13.4.2. 主类Game13.4.3. 方块 Block13.4.4. 雷区 MineSquare13.4.5. 雷标数目 FindAroundMineMarkNumber13.4.6. 雷标判断 DetermineMineMarkIsRightOrWrong13.4.7. 成片挖开区域 DetermineDigArea13.4.8. 无雷连通区 FindSafeArea13.4.9. 随机布雷 RandomSetMine13.4.10. 周围地雷个数FindAroundMineNumber13.4.11. 显示剩余雷数CountMine13.4.12. 计时器TimeCount13.4.13. 英雄榜录入对话框Record13.4.14. 显示英雄榜对话框ShowRecord13.4.15. 挖雷成功DecideWinner13.5. 课程设计作业第14章 网络聊天室 (B/S模式)14.1. 设计内容14.2. 设计要求14.3. 总体设计14.4. 具体设计14.4.1. 运行效果与程序发布14.4.2. 客户端主类ClientChat14.4.3. 客户端输入妮称界面InputNameTextField14.4.4. 客户端聊天界面ChatArea14.4.5. 服务器端主类ChatServer14.5. 课程设计作业第15章 局域网络广播系统15.1. 设计内容15.2. 设计要求15.3. 总体设计15.4. 具体设计15.4.1. 运行效果与程序发布15.4.2. 客户端主类Receive15.4.3. 服务器端主类BroadCastWord15.5. 课程设计作业
评论 35
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值