• javafx+JDBC实现新生报到管理系统


    🍅程序员小王的博客:程序员小王的博客
    🍅 欢迎点赞 👍 收藏 ⭐留言 📝
    🍅 如有编辑错误联系作者,如果有比较好的文章欢迎分享给我,我会取其精华去其糟粕
    🍅java自学的学习路线:java自学的学习路线

    一、前言

    今天有个同学想实现《javafx+JDBC实现新生报到管理系统》,然后我根据网上的一个学生管理系统给他简单修改实现了一下,主要使用JDBC+javafx实现,然后主要是通过数据库账户和密码登录系统,然后分老师和学生,学生通过学号查询自己的信息,可以修改自己的信息,老师可以增加学院,班级,学生信息等

    二、项目具体实现图+源码展示

    1、登录页面

    数据库名为当前项目连接的数据库名,用户名和密码为mysql的账户和密码

    • fxml_Login.fxml
    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" 
      minHeight="-Infinity" minWidth="-Infinity" 
      prefHeight="300.0" prefWidth="450.0" style="-fx-background-color: #87CEFA;" 
      xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" 
      fx:controller="control.LoginControl">
      
       <children>
          <ImageView layoutX="20.0" layoutY="73.0">
             <image>
                <Image url="@../image/Login_user.png" />
             </image>
          </ImageView>
          <Label layoutX="160.0" layoutY="125.0" text="用户名" textAlignment="CENTER">
             <font>
                <Font size="20.0" />
             </font>
          </Label>
          <Label layoutX="177.0" layoutY="165.0" text="密码" textAlignment="CENTER">
             <font>
                <Font size="20.0" />
             </font>
          </Label>
          <TextField fx:id="text_userName" layoutX="235.0" layoutY="125.0" promptText="请输入数据库用户名" text="root">
             <font>
                <Font name="System Italic" size="15.0" />
             </font>
          </TextField>
          <PasswordField fx:id="text_password" layoutX="235.0" layoutY="165.0" promptText="请输入数据库密码" />
          <Button fx:id="btn_login" layoutX="356.0" layoutY="206.0" mnemonicParsing="false" onAction="#loginDataBase" prefHeight="30.0" prefWidth="80.0" text="登录" textFill="RED">
             <font>
                <Font size="18.0" />
             </font>
          </Button>
          <Label contentDisplay="CENTER" layoutX="106.0" layoutY="214.0" text="萌新,贵州师范学院欢迎你!" textAlignment="CENTER" wrapText="true">
             <font>
                <Font size="14.0" />
             </font>
          </Label>
          <ImageView fitHeight="32.0" fitWidth="32.0" layoutX="4.0" layoutY="255.0">
             <image>
                <Image url="@../image/time.png" />
             </image>
          </ImageView>
          <ImageView fitHeight="32.0" fitWidth="32.0" layoutX="234.0" layoutY="254.0">
             <image>
                <Image url="@../image/IP.png" />
             </image>
          </ImageView>
          <TextField fx:id="text_time" alignment="CENTER" disable="true" editable="false" layoutX="39.0" layoutY="253.0" prefHeight="34.0" prefWidth="150.0" text="1970年1月1日">
             <font>
                <Font size="16.0" />
             </font>
          </TextField>
          <TextField fx:id="text_IP" alignment="CENTER" disable="true" editable="false" layoutX="266.0" layoutY="253.0" prefHeight="34.0" prefWidth="140.0" text="192.168.0.1">
             <font>
                <Font size="16.0" />
             </font>
          </TextField>
          <Label alignment="CENTER" contentDisplay="CENTER" layoutX="135.0" layoutY="23.0" text="欢迎使用新生报到管理系统" textAlignment="CENTER" wrapText="true">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <Label layoutX="160.0" layoutY="85.0" text="数据库">
             <font>
                <Font size="20.0" />
             </font>
          </Label>
          <TextField fx:id="text_DataBaseName" layoutX="235.0" layoutY="84.0" promptText="请输入数据库名称" text="newstudent" />
       </children>
    </AnchorPane>
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 连接数据库

    • public class DataBase {
      
        Connection connection = null;
        ResultSet rs = null;
      
        //mysql数据库url
        private static String DateBaseName=null;
        private static String userMySql=null;
        private static String passwordMySql=null;
        private static String urlMySql = null;
      
        public DataBase() {
      
          try {
            //mysql数据库设置驱动程序类型
            Class.forName("com.mysql.cj.jdbc.Driver");
            System.out.println("mysql数据库驱动加载成功");
      
            //sqlserver数据库设置驱动程序类型
            //Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            //System.out.println("sqlserver数据库驱动加载成功");
      
          }
          catch(java.lang.ClassNotFoundException e) {
            e.printStackTrace();
          }
        }
      
        public DataBase(String DataBaseName,String userName,String password)
        {
          this();
          DataBase.DateBaseName=DataBaseName;
          DataBase.userMySql=userName;
          DataBase.passwordMySql=password;
      
          urlMySql = "jdbc:mysql://localhost:3306/"+DateBaseName+"?user="
              +userMySql+"&password="+passwordMySql + "&useUnicode=true&characterEncoding=utf-8";
        }
      
        public boolean connect()
        {
          if(urlMySql==null)
          {
            return false;
          }
      
          try{
            //mysql数据库
            connection = DriverManager.getConnection(urlMySql);
      
            //sqlserver数据库
            //connection = DriverManager.getConnection(urlSqlServer);
      
            if(connection!=null){
              System.out.println("数据库连接成功");
              return true;
            }
            return false;
          }
          catch(Exception e){
      
            //e.printStackTrace();
            System.out.println("数据库连接失败");
            return false;
          }
        }
      
        public void disconnect(){
          try{
            if(connection != null){
              connection.close();
              connection = null;
            }
          }
          catch(Exception e){
            e.printStackTrace();
          }
        }
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
      • 26
      • 27
      • 28
      • 29
      • 30
      • 31
      • 32
      • 33
      • 34
      • 35
      • 36
      • 37
      • 38
      • 39
      • 40
      • 41
      • 42
      • 43
      • 44
      • 45
      • 46
      • 47
      • 48
      • 49
      • 50
      • 51
      • 52
      • 53
      • 54
      • 55
      • 56
      • 57
      • 58
      • 59
      • 60
      • 61
      • 62
      • 63
      • 64
      • 65
      • 66
      • 67
      • 68
      • 69
      • 70
      • 71
      • 72
      • 73
      • 74
      • 75
      • 76
      • 77
      • 78

    2、选择老师还是学生

    • fxml_Login.fxml
    <HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="control.SelectControl">
       <children>
          <Button fx:id="btn_Teacher" contentDisplay="CENTER" mnemonicParsing="false" onAction="#selectTeacher" prefHeight="300.0" prefWidth="300.0" style="-fx-background-color: #FFC0CB;" text="我是老师" textAlignment="CENTER" wrapText="true">
             <font>
                <Font size="72.0" />
             </font>
          </Button>
          <Separator orientation="VERTICAL" prefHeight="300.0" />
          <Button fx:id="btn_Student" contentDisplay="CENTER" mnemonicParsing="false" onAction="#selectStudent" prefHeight="300.0" prefWidth="300.0" style="-fx-background-color: #90EE90;" text="我是学生" textAlignment="CENTER" wrapText="true">
             <font>
                <Font size="72.0" />
             </font>
          </Button>
       </children>
    </HBox>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    3、学生功能

    点击我是学生,然后进入学生页面,因为学生是新生,不需要账户和密码登录,学校给学生分配了学号的,我们输入自己的学号,点击查询,就能查询自己的个人信息了

    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="410.0" prefWidth="500.0" style="-fx-background-color: #FFF8DC;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="control.StudentControl">
       <children>
          <Label layoutX="94.0" layoutY="15.0" text="学号" textAlignment="CENTER" textOverrun="CENTER_ELLIPSIS" wrapText="true">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <TextField fx:id="text_StudentID" layoutX="148.0" layoutY="12.0" promptText="请输入学号查询自己的信息" />
          <Button fx:id="btn_Select" layoutX="366.0" layoutY="12.0" mnemonicParsing="false" onAction="#selcetData" text="查询" />
          <Label layoutX="148.0" layoutY="72.0" text="姓名">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <TextField fx:id="text_Name" layoutX="189.0" layoutY="69.0" prefHeight="30.0" prefWidth="100.0" />
          <Label layoutX="330.0" layoutY="72.0" text="性别">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <ComboBox fx:id="comboBox_Sex" layoutX="373.0" layoutY="69.0" prefHeight="30.0" prefWidth="80.0" />
          <Label layoutX="148.0" layoutY="124.0" text="生日">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <Label layoutX="148.0" layoutY="176.0" text="籍贯">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <TextField fx:id="text_Birthday" layoutX="189.0" layoutY="121.0" prefHeight="30.0" prefWidth="120.0" />
          <TextField fx:id="text_NativePlace" layoutX="189.0" layoutY="173.0" prefHeight="30.0" prefWidth="175.0" />
          <Label layoutX="60.0" layoutY="235.0" text="班级">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <Button fx:id="btn_updata" layoutX="209.0" layoutY="366.0" mnemonicParsing="false" onAction="#upData" text="更新" textFill="RED" visible="false">
             <font>
                <Font size="18.0" />
             </font>
          </Button>
          <ComboBox fx:id="comboBox_Class" layoutX="110.0" layoutY="235.0" prefWidth="150.0" />
          <Label layoutX="277.0" layoutY="235.0" text="学籍">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <TextField fx:id="text_Change" disable="true" editable="false" layoutX="318.0" layoutY="235.0" prefHeight="30.0" prefWidth="65.0" />
          <Label layoutX="60.0" layoutY="285.0" text="院系">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <ComboBox fx:id="comboBox_Department" layoutX="110.0" layoutY="285.0" prefHeight="30.0" prefWidth="330.0" />
          <Label layoutX="60.0" layoutY="335.0" text="奖励">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <TextField fx:id="text_Reward" editable="false" layoutX="110.0" layoutY="330.0" prefHeight="30.0" prefWidth="150.0" />
          <Label layoutX="277.0" layoutY="335.0" text="处分">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <TextField fx:id="text_Punishment" editable="false" layoutX="318.0" layoutY="330.0" prefHeight="30.0" prefWidth="120.0" />
          <ImageView layoutX="-4.0" layoutY="70.0">
             <image>
                <Image url="@../image/picture.png" />
             </image>
          </ImageView>
          <Button fx:id="btn_more" layoutX="332.0" layoutY="121.0" mnemonicParsing="false" onAction="#moreInfo" text="更多信息" textFill="#001eff" visible="false" />
       </children>
    </AnchorPane>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 查询出来个人信息

    *

     点击更多信息查看自己是否有奖学金
    
    • 1

    • 可以修改自己的生日,籍贯等,电商不能修改学院班级

    4、老师功能

    点击进入我是老师,进入学生学籍管理系统,可以查看所有学生信息

    • 点击编辑可以新增学生,修改学生信息,也可以删除学生,也可以退出系统

    • MenuItem menu_add = new MenuItem("新增");
          menu_add.setGraphic(new ImageView(new Image("image/add.png")));
          menu_add.setOnAction((ActionEvent t) -> {
            addStudent(t);
          });
      
      
      
          MenuItem menu_modify = new MenuItem("修改");
          menu_modify.setGraphic(new ImageView(new Image("image/modify.png")));
          menu_modify.setOnAction((ActionEvent t) -> {
            modifyStudent(t);
          });
      
          MenuItem menu_delete = new MenuItem("删除");
          menu_delete.setGraphic(new ImageView(new Image("image/delete.png")));
          menu_delete.setOnAction((ActionEvent t) -> {
            deleteStudent(t);
          });
          MenuItem menu_exit = new MenuItem("退出");
          menu_exit.setGraphic(new ImageView(new Image("image/exit.png")));
          menu_exit.setOnAction((ActionEvent t) -> {
            System.exit(0);
          });
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
    • 点击新增

    • 新增后

    • 如果学生比较多,也可以通过学号,姓名,班级,院系查看学生信息

    @Override
      public void initialize(URL location, ResourceBundle resources) {
    
        //布局初始化
        HBox_bottom.setAlignment(Pos.CENTER);
        HBox_application.setAlignment(Pos.CENTER);
    
        text_select.setText("点击查询返回全部信息");
    
        //表格初始化
        tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);//表格自动填充
        data =FXCollections.observableArrayList();//数据
        tableView.setItems(data);//添加数据
        tableView.setStyle( "-fx-alignment: CENTER;");
        data.clear();
        data.addAll(Person.getPeopleFromSQL(Student.getStudentIDFromSQL()));
    
        //每一列初始化
        InitTableColumes();
    
    
        //标签初始化
        Date date =new Date();
        DateFormat longFormat=DateFormat.getDateInstance(DateFormat.LONG);
    
        InetAddress localAddress=null;
        try {
          localAddress=InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
    
        label_IP.setText(localAddress.getHostAddress());
        label_IP.setTooltip(new Tooltip("本机IP"));
        label_time.setText(longFormat.format(date));
        label_time.setTooltip(new Tooltip("当前时间"));
    
        //下拉栏初始化
        ObservableList<String> Options =
            FXCollections.observableArrayList(optionsName);
        comboBox.setItems(Options);
        comboBox.setTooltip(new Tooltip("选择一个查询项"));
    
        //菜单栏初始化
        //编辑栏
        MenuItem menu_add = new MenuItem("新增");
        menu_add.setGraphic(new ImageView(new Image("image/add.png")));
        menu_add.setOnAction((ActionEvent t) -> {
          addStudent(t);
        });
    
    
    
        MenuItem menu_modify = new MenuItem("修改");
        menu_modify.setGraphic(new ImageView(new Image("image/modify.png")));
        menu_modify.setOnAction((ActionEvent t) -> {
          modifyStudent(t);
        });
    
        MenuItem menu_delete = new MenuItem("删除");
        menu_delete.setGraphic(new ImageView(new Image("image/delete.png")));
        menu_delete.setOnAction((ActionEvent t) -> {
          deleteStudent(t);
        });
        MenuItem menu_exit = new MenuItem("退出");
        menu_exit.setGraphic(new ImageView(new Image("image/exit.png")));
        menu_exit.setOnAction((ActionEvent t) -> {
          System.exit(0);
        });
    
        menu_edit.getItems().addAll(menu_add,menu_modify,menu_delete,menu_exit);
    
        //帮助栏
        MenuItem menu_FU = new MenuItem("教师队伍");
        menu_FU.setOnAction((ActionEvent t) ->
        {
          gotoFuWebpage();
        });
    
        MenuItem menu_MO = new MenuItem("学校官网");
        menu_MO.setOnAction((ActionEvent t) ->
        {
          gotoMoWebPage();
    
        });
        menu_help.getItems().addAll(menu_FU,menu_MO);
    
      }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90

    三、数据库设计文档

    有六张表

    数据库名: newstudent

    文档版本: V1.0.0

    文档描述: 新生入学管理系统数据库表设计描述

    表名说明
    class专业班级
    department学院
    mychange改变
    punishment惩罚
    reward奖学金
    student学生信息

    表名: class

    说明:

    数据列:

    序号名称数据类型长度小数位允许空值主键默认值说明
    1IDchar120NY
    2Namechar450YN
    3Monitorchar120YN

    表名: department

    说明:

    数据列:

    序号名称数据类型长度小数位允许空值主键默认值说明
    1IDchar120NY
    2Namechar1500YN

    表名: mychange

    说明:

    数据列:

    序号名称数据类型长度小数位允许空值主键默认值说明
    1IDchar240NY
    2StudentIDchar120YN
    3MyChangeint100YN
    4Rec_Timechar120YN
    5Descriptionchar900YN

    表名: punishment

    说明:

    数据列:

    序号名称数据类型长度小数位允许空值主键默认值说明
    1IDchar240NY
    2StudentIDchar120YN
    3Levelsint100YN
    4Rec_Timechar120YN
    5Enablebit10YN
    6Descriptionchar900YN

    表名: reward

    说明:

    数据列:

    序号名称数据类型长度小数位允许空值主键默认值说明
    1IDchar240NY
    2StudentIDchar120YN
    3Levelsint100YN
    4Rec_Timechar120YN
    5Descriptionchar900YN

    表名: student

    说明:

    数据列:

    序号名称数据类型长度小数位允许空值主键默认值说明
    1StudentIDchar120NY
    2Namechar120YN
    3Sexchar60YN
    4Classchar120YN
    5Departmentchar120YN
    6Birthdaychar120YN
    7Native_Placechar240YN

    四、mysql数据库和源码下载

    新生报道的源码下载地址:https://download.csdn.net/download/weixin_44385486/85788775

    image_-OQICr6BJT

  • 相关阅读:
    python多线程技术(Threading)
    类类型参数函数调用发生了什么
    华为欧拉 openEuler 23.09 一键安装 Oracle 12CR2 单机
    【附源码】计算机毕业设计JAVA专利查询与发布系统设计与实现
    《前端》JavaScript总结
    三、创建脚手架和脚手架分析
    jmeter发送请求参数如何使用变量
    每日Leecode算法题:1337.矩阵中战斗力最弱的k行
    2023最新SSM计算机毕业设计选题大全(附源码+LW)之java星河书城9p6tr
    修改ant-design-vue的switch样式,去除顿顿的样式
  • 原文地址:https://blog.csdn.net/weixin_44385486/article/details/125474901