当前位置:   article > 正文

java图形界面swing 连接sql server数据库 实现学生课程成绩管理系统(适用于课设、大作业)_学生成绩管理系统java和sql

学生成绩管理系统java和sql

效果演示:点击此处跳转
之前做了一个外卖点餐系统之后点此查看详情,这段时间在这个系统的基础上改了改帮几位同学实现了其他的几个系统,本文所述的学生课程成绩管理系统就是其中之一。
一、数据库表及字段
1、学生表
在这里插入图片描述

2、课程表
在这里插入图片描述

3、成绩表
在这里插入图片描述

4、管理员表
在这里插入图片描述
二、系统运行界面图(部分)
1、登陆界面
在这里插入图片描述

2、管理员首界面
在这里插入图片描述

3、成绩统计界面
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
并将统计结果写入外部文件:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4、学生管理界面
在这里插入图片描述

管理中心里面的功能基本都差不多,所以就列举上面几个,下面展示主要代码。
三、部分核心代码
1、登录功能

String url = "jdbc:sqlserver://localhost:1433;DatabaseName=student_course_grade";
    String username = "sa"; 
    String password = "123";
    Connection connection = null;
    PreparedStatement ps=null;
	private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JScrollPane jScrollPane1;
    private JTextField jTextField1;
    private javax.swing.JToggleButton jToggleButton1;  
	
	public guanlidenglu() {
   
        initComponents();
    }                         
    
	private void connectdb() {
   
		try {
    
	           Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver" );
	           connection = DriverManager.getConnection(url, username, password ); 
	        } 
	        catch ( ClassNotFoundException cnfex ) {
    
	           System.err.println( 
	              "装载 JDBC/ODBC 驱动程序失败。" ); 
	           cnfex.printStackTrace(); 
	           System.exit( 1 ); 
	        } 
	        catch ( SQLException sqlex ) {
    
	           System.err.println( "无法连接数据库" ); 
	           sqlex.printStackTrace(); 
	           System.exit( 1 );
	        }
	}
	
	private void initComponents() {
   

        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jToggleButton1 = new javax.swing.JToggleButton();
        jButton3 = new javax.swing.JButton();
        jPasswordField1 = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel2.setBackground(new java.awt.Color(120, 150, 190));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "学生成绩管理系统", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("微软雅黑", 1, 24), new java.awt.Color(255, 255, 255))); // NOI18N
        jPanel2.setAutoscrolls(true);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("账号:");

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("密码:");

        jTextField1.setColumns(20);
        jScrollPane1.setViewportView(jTextField1);

        jButton1.setText("登录");

        jButton2.setText("注册");

        jToggleButton1.setText("退出");
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
   
            public void actionPerformed(java.awt.event.ActionEvent evt) {
   
                jToggleButton1ActionPerformed(evt);
            }
        });
        
        jButton1.addActionListener(new java.awt.event.ActionListener() {
   
            public void actionPerformed(java.awt.event.ActionEvent evt) {
   
                try {
   
					jButton1ActionPerformed(evt);
				} catch (SQLException e) {
   
					e.printStackTrace();
				}
            }
        });
        
        jButton2.addActionListener(new java.awt.event.ActionListener() {
   
            public void actionPerformed(java.awt.event.ActionEvent evt) {
   
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("帮助");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
   
            public void actionPerformed(java.awt.event.ActionEvent evt) {
   
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jToggleButton1))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(162, 162, 162)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jButton1)
                        .addGap(85, 85, 85)
                        .addComponent(jButton2))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPasswordField1, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)))
                .addContainerGap(171, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(69, 69, 69)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(36, 36, 36)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 118, Short.MAX_VALUE)
                .addComponent(jToggleButton1))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(113, 113, 113)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(290, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(441, Short.MAX_VALUE))
        );

        pack();
    }                       

    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
                                                  
        System.exit(0);
    }  
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) throws SQLException {
    
    	String Ausername=jTextField1.getText();
    	String Apassword=jPasswordField1.getText();
    	connectdb();
        String sql="select adminName,adminPassword from admin where adminName='"+Ausername+"' and adminPassword='"+Apassword+"'";
        ps=connection.prepareStatement(sql);
        ResultSet rs=ps.executeQuery();
        if(rs.next()) {
   
        	guanlidenglu.this.setVisible(false);
            guanli Guanli=new guanli();
            Guanli.setVisible(true);
        }
        else {
   
        	JOptionPane.showMessageDialog(null,"密码或用户名错误!!!!");
        } 
        connection.close();
    }
    
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
                                            
    	JOptionPane.showMessageDialog(null,"请联系BOSS申请管理员!!!");
    }

    
    public static void main(String args[]) {
   
        
  • 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
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/790201
推荐阅读
相关标签
  

闽ICP备14008679号