学生成绩管理系统java+mysql+swing入门级项目开发

夫陶公清风千古,余又何人,敢称庶几
在这里插入图片描述


代码已移至Gitee :
https://gitee.com/BreezAm/edu-student

文章目录

  • 简要:
    • 登陆运行效果
    • 主界面运行效果图
    • 界面设置运行效果图
    • 网络配置界面运行效果图
    • 菜单栏运行效果图
    • 登陆窗体实现
    • 窗体界面设置功能对话框
    • 网络配置对话框实现代码
    • 主窗体实现
    • 字符串判空工具代码
    • 学生信息模型
    • 用户登陆信息模型
    • 界面修改模型
    • 数据库后台实现

简要:

今天做了一个1800行代码的学生成绩管理系统,主要实现增删改查等操作,还大部分功能尚未实现,这个项目是基于java+swing+jdbc+mysql的融合,主要对学习过的知识进行综合的复习,如果项目中有bug的地方,可以在评论区留言,在此谢过。

登陆运行效果

该登陆只能管理员登陆,当用户输入账号和密码时,会与数据库中的信息进行对比,如果信息无误,销毁登陆对话框,显示主窗体,如果输入错误,提示信息并则清空文本框,继续输入。
在这里插入图片描述

主界面运行效果图

在这里插入图片描述

界面设置运行效果图

此功能为修改窗体大小,背景颜色,位置,标题,没有提供代码,留给感兴趣的靓仔实现

在这里插入图片描述

网络配置界面运行效果图

此功能主要用来远程连接数据库,,未提供实现代码。
在这里插入图片描述

菜单栏运行效果图

在这里插入图片描述

登陆窗体实现

package com.student.frame;
import com.student.Data.Dao;
import com.student.modal.User;
import com.student.util.StringUtil;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
public class Login extends JDialog {private JTextField userField;private JPasswordField passwordField;public Login() {try {setVisible(true);setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);} catch (Exception e) {e.printStackTrace();}setTitle("学生成绩管理系统");setResizable(false);setSize( 545, 381);setLocationRelativeTo(null);getContentPane().setLayout(null);JLabel label = new JLabel("用户登录");label.setHorizontalAlignment(SwingConstants.CENTER);label.setFont(new Font("Dialog", Font.BOLD, 30));label.setBounds(12, 0, 521, 85);getContentPane().add(label);JLabel label_1 = new JLabel("账    号:");label_1.setIcon(new ImageIcon(Login.class.getResource("/icon/user4.png")));label_1.setFont(new Font("Dialog", Font.BOLD, 15));label_1.setBounds(92, 166, 98, 32);getContentPane().add(label_1);JLabel label_2 = new JLabel("密    码:");label_2.setIcon(new ImageIcon(Login.class.getResource("/icon/psw3.png")));label_2.setFont(new Font("Dialog", Font.BOLD, 15));label_2.setBounds(92, 210, 98, 32);getContentPane().add(label_2);userField = new JTextField();userField.setBounds(191, 173, 240, 22);getContentPane().add(userField);userField.setColumns(10);passwordField = new JPasswordField();passwordField.setEchoChar('*');passwordField.setBounds(191, 218, 240, 22);getContentPane().add(passwordField);JButton ok = new JButton(" ");//登陆事件ok.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {if(StringUtil.isEmpy(userField.getText())){JOptionPane.showMessageDialog(null, "账号不能为空");return;}else if(StringUtil.isEmpy(new String(passwordField.getPassword()))){JOptionPane.showMessageDialog(null, "密码不能为空");return;}else {User u=new User();u.setUser(Double.parseDouble(userField.getText()));u.setPassword(new String(passwordField.getPassword()));try {User user = Dao.checkLogin(u);if(user!=null) {JOptionPane.showMessageDialog(null, "登陆成功");dispose();new MainWindow().setVisible(true);}else {JOptionPane.showMessageDialog(null, "账号或密码有误");userField.setText("");passwordField.setText("");return;}} catch (SQLException e) {e.printStackTrace();}}}});ok.setIcon(new ImageIcon(Login.class.getResource("/icon/exit2.png")));ok.setBounds(155, 285, 73, 32);getContentPane().add(ok);JButton cancel = new JButton(" ");//退出系统事件cancel.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {System.exit(0);}});passwordField.addKeyListener(new java.awt.event.KeyAdapter() {public void keyTyped(java.awt.event.KeyEvent e) {if(e.getKeyChar()=='\n') {ok.doClick(10);}}});cancel.setIcon(new ImageIcon(Login.class.getResource("/icon/exite1.png")));cancel.setBounds(358, 285, 73, 32);getContentPane().add(cancel);JLabel lblNewLabel = new JLabel("登陆背景");lblNewLabel.setIcon(new ImageIcon(Login.class.getResource("/iimages/timg2.jpeg")));lblNewLabel.setBounds(0, -54, 545, 405);getContentPane().add(lblNewLabel);}
}

窗体界面设置功能对话框

package com.student.frame;import java.awt.BorderLayout;
import java.awt.FlowLayout;import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.Font;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;public class ThemeFrame extends JDialog {private final JPanel contentPanel = new JPanel();private JTextField textField;private JTextField textField_1;private JTextField textField_2;private JTextField textField_3;private JTextField textField_4;public ThemeFrame() {setModal(true);setResizable(false);try {setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);setVisible(false);} catch (Exception e) {e.printStackTrace();}setTitle("主题修改");setSize(423, 416);setLocationRelativeTo(null);getContentPane().setLayout(new BorderLayout());contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));getContentPane().add(contentPanel, BorderLayout.CENTER);JComboBox backgroundBox = new JComboBox();JLabel background = new JLabel("窗口背景:");background.setFont(new Font("Dialog", Font.BOLD, 15));JLabel title = new JLabel("标        题:");title.setFont(new Font("Dialog", Font.BOLD, 15));textField = new JTextField();textField.setColumns(15);JLabel label = new JLabel("窗口大小:");label.setFont(new Font("Dialog", Font.BOLD, 15));textField_1 = new JTextField();textField_1.setText(" ");textField_1.setColumns(5);JLabel lblNewLabel_2 = new JLabel("X:");JLabel lblY = new JLabel("Y:");textField_2 = new JTextField();textField_2.setText(" ");textField_2.setColumns(5);JLabel label_1 = new JLabel("窗口位置:");label_1.setFont(new Font("Dialog", Font.BOLD, 15));JLabel lblX = new JLabel("X:");textField_3 = new JTextField();textField_3.setText(" ");textField_3.setColumns(5);JLabel lblY_1 = new JLabel("Y:");textField_4 = new JTextField();textField_4.setText(" ");textField_4.setColumns(5);JButton apllyAndClose = new JButton("应用和关闭");apllyAndClose.setIcon(new ImageIcon(ThemeFrame.class.getResource("/icon/应用.png")));/*** 主题修改单机事件* */apllyAndClose.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {dispose();}});JButton Default = new JButton("默认");Default.setIcon(new ImageIcon(ThemeFrame.class.getResource("/icon/默认.png")));GroupLayout gl_contentPanel = new GroupLayout(contentPanel);gl_contentPanel.setHorizontalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addContainerGap().addGroup(gl_contentPanel.createParallelGroup(Alignment.TRAILING).addGroup(gl_contentPanel.createSequentialGroup().addComponent(background).addPreferredGap(ComponentPlacement.RELATED).addComponent(backgroundBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addContainerGap(283, Short.MAX_VALUE)).addGroup(gl_contentPanel.createSequentialGroup().addComponent(label).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addComponent(lblY).addComponent(lblNewLabel_2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addGap(31).addComponent(label_1)).addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addComponent(lblX).addComponent(lblY_1)).addGap(3).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(36)).addGroup(gl_contentPanel.createSequentialGroup().addComponent(title).addPreferredGap(ComponentPlacement.RELATED).addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addContainerGap()).addGroup(gl_contentPanel.createSequentialGroup().addComponent(Default).addPreferredGap(ComponentPlacement.RELATED, 237, Short.MAX_VALUE).addComponent(apllyAndClose).addContainerGap()))));gl_contentPanel.setVerticalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addGap(34).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(background).addComponent(backgroundBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(title).addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(27).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(label).addComponent(lblNewLabel_2).addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(label_1).addComponent(lblX).addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(lblY).addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))).addGroup(gl_contentPanel.createSequentialGroup().addGap(25).addComponent(lblY_1)).addGroup(gl_contentPanel.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED).addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))).addPreferredGap(ComponentPlacement.RELATED, 115, Short.MAX_VALUE).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(apllyAndClose).addComponent(Default)).addGap(38)));contentPanel.setLayout(gl_contentPanel);{JPanel buttonPane = new JPanel();buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));getContentPane().add(buttonPane, BorderLayout.SOUTH);}}
}

网络配置对话框实现代码

package com.student.modal;import java.awt.BorderLayout;
import java.awt.FlowLayout;import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ImageIcon;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;public class InternetConfigFrame extends JDialog {private final JPanel contentPanel = new JPanel();private JTextField textField;private JTextField textField_1;private JTextField textField_2;private JTextField textField_3;private JTextField textField_4;public InternetConfigFrame() {try {setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);setVisible(false);} catch (Exception e) {e.printStackTrace();}setResizable(false);setModal(true);setTitle("MySQL 新建连接");setSize(591, 556);setLocationRelativeTo(null);getContentPane().setLayout(new BorderLayout());contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));getContentPane().add(contentPanel, BorderLayout.CENTER);JPanel panel = new JPanel();panel.setBackground(Color.WHITE);panel.setBorder(new LineBorder(Color.LIGHT_GRAY, 5));JLabel label_2 = new JLabel("连接名:");textField = new JTextField();textField.setColumns(30);JLabel label_3 = new JLabel("主机:");JLabel lblNewLabel_5 = new JLabel("端口");JLabel label_4 = new JLabel("用户名:");JLabel label_5 = new JLabel("密码:");textField_1 = new JTextField();textField_1.setColumns(10);textField_2 = new JTextField();textField_2.setColumns(10);textField_3 = new JTextField();textField_3.setColumns(10);textField_4 = new JTextField();textField_4.setColumns(10);JCheckBox chckbxNewCheckBox = new JCheckBox("保存密码");JPanel panel_1 = new JPanel();panel_1.setBorder(new LineBorder(Color.WHITE, 2));GroupLayout gl_contentPanel = new GroupLayout(contentPanel);gl_contentPanel.setHorizontalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addGap(22).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addComponent(panel, GroupLayout.PREFERRED_SIZE, 539, GroupLayout.PREFERRED_SIZE).addContainerGap()).addGroup(gl_contentPanel.createSequentialGroup().addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addComponent(label_2).addComponent(label_3).addComponent(lblNewLabel_5).addComponent(label_4).addComponent(label_5)).addGap(75).addGroup(gl_contentPanel.createParallelGroup(Alignment.TRAILING).addComponent(textField, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE).addComponent(textField_1, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE).addComponent(textField_2, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addGroup(Alignment.LEADING, gl_contentPanel.createParallelGroup(Alignment.TRAILING, false).addComponent(textField_4, Alignment.LEADING).addComponent(textField_3, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE).addComponent(chckbxNewCheckBox, Alignment.LEADING))).addGap(58)))).addGroup(gl_contentPanel.createSequentialGroup().addContainerGap().addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 569, GroupLayout.PREFERRED_SIZE).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));gl_contentPanel.setVerticalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addComponent(panel, GroupLayout.PREFERRED_SIZE, 114, GroupLayout.PREFERRED_SIZE).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addGap(38).addComponent(label_2)).addGroup(gl_contentPanel.createSequentialGroup().addGap(26).addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))).addGap(26).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(label_3).addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(29).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_5).addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(26).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(label_4).addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(18).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(label_5).addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(18).addComponent(chckbxNewCheckBox).addGap(26).addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE).addContainerGap()));JButton button = new JButton("测试连接");button.setIcon(new ImageIcon(InternetConfigFrame.class.getResource("/icon/测试 检测.png")));JButton button_1 = new JButton("确定");button_1.setIcon(new ImageIcon(InternetConfigFrame.class.getResource("/icon/应用.png")));JButton button_2 = new JButton("取消");button_2.setIcon(new ImageIcon(InternetConfigFrame.class.getResource("/icon/取消.png")));button_2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {dispose();//销毁对话框}});GroupLayout gl_panel_1 = new GroupLayout(panel_1);gl_panel_1.setHorizontalGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, gl_panel_1.createSequentialGroup().addContainerGap().addComponent(button, GroupLayout.PREFERRED_SIZE, 143, GroupLayout.PREFERRED_SIZE).addPreferredGap(ComponentPlacement.RELATED, 277, Short.MAX_VALUE).addComponent(button_1).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(button_2).addGap(5)));gl_panel_1.setVerticalGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, gl_panel_1.createSequentialGroup().addContainerGap(18, Short.MAX_VALUE).addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING).addComponent(button).addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(button_1).addComponent(button_2))).addContainerGap()));panel_1.setLayout(gl_panel_1);JLabel lblNewLabel = new JLabel("Navicat");JLabel lblNewLabel_1 = new JLabel(" ");lblNewLabel_1.setIcon(new ImageIcon(InternetConfigFrame.class.getResource("/icon/连接.png")));JLabel lblNewLabel_2 = new JLabel("数据库");JLabel lblNewLabel_3 = new JLabel(" ");lblNewLabel_3.setIcon(new ImageIcon(InternetConfigFrame.class.getResource("/icon/数据库.png")));JLabel lblNewLabel_4 = new JLabel(" ");lblNewLabel_4.setIcon(new ImageIcon(InternetConfigFrame.class.getResource("/icon/直线_图形对象_jurassic.png")));JLabel label = new JLabel(" ");label.setIcon(new ImageIcon(InternetConfigFrame.class.getResource("/icon/直线_图形对象_jurassic.png")));JLabel label_1 = new JLabel(" ");label_1.setIcon(new ImageIcon(InternetConfigFrame.class.getResource("/icon/直线_图形对象_jurassic.png")));GroupLayout gl_panel = new GroupLayout(panel);gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel.createSequentialGroup().addGap(150).addGroup(gl_panel.createParallelGroup(Alignment.TRAILING).addComponent(lblNewLabel).addComponent(lblNewLabel_1)).addPreferredGap(ComponentPlacement.RELATED).addComponent(label_1, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE).addPreferredGap(ComponentPlacement.RELATED).addComponent(lblNewLabel_4).addPreferredGap(ComponentPlacement.RELATED).addComponent(label, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE).addPreferredGap(ComponentPlacement.RELATED, 31, Short.MAX_VALUE).addGroup(gl_panel.createParallelGroup(Alignment.LEADING).addComponent(lblNewLabel_3).addComponent(lblNewLabel_2)).addGap(152)));gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup().addContainerGap(19, Short.MAX_VALUE).addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_3).addComponent(lblNewLabel_1)).addGap(18).addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel).addComponent(lblNewLabel_2)).addGap(27)).addGroup(gl_panel.createSequentialGroup().addGap(44).addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(label_1, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE).addComponent(lblNewLabel_4, GroupLayout.PREFERRED_SIZE, 21, Short.MAX_VALUE).addComponent(label, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)).addContainerGap()));panel.setLayout(gl_panel);contentPanel.setLayout(gl_contentPanel);{JPanel buttonPane = new JPanel();buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));getContentPane().add(buttonPane, BorderLayout.SOUTH);}JMenuBar menuBar = new JMenuBar();setJMenuBar(menuBar);JMenu menu = new JMenu("常规");menuBar.add(menu);}
}

主窗体实现

package com.student.frame;import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.util.List;
import java.util.Vector;import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;import com.student.Data.Dao;
import com.student.modal.InternetConfigFrame;
import com.student.modal.StudentData;
import com.student.util.StringUtil;import javax.swing.JToolBar;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.FlowLayout;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import javax.swing.ImageIcon;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Color;
import javax.swing.UIManager;
import javax.swing.JLabel;
import javax.swing.border.TitledBorder;
import javax.swing.border.LineBorder;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;public class MainWindow extends JFrame {/*** 表单*/private static JTable table;/*** 文本域*/private JTextField stuField;private JTextField nameField;private JTextField ageField;private JTextField mathField;private JTextField javaField;private JTextField cField;private JTextField englishField;private JRadioButton radioMan;private JRadioButton radioFemal;private final ButtonGroup buttonGroup = new ButtonGroup();public static void main(String[] args) {try {MainWindow frame = new MainWindow();frame.setVisible(false);} catch (Exception e) {e.printStackTrace();}}public MainWindow() {new Login();setFont(new Font("Dialog", Font.PLAIN, 18));setTitle("学生成绩管理系统");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100, 100, 800, 600);setLocationRelativeTo(null);JMenuBar menuBar = new JMenuBar();setJMenuBar(menuBar);JMenu menu = new JMenu("基本信息");/*** * 主页监听事件* */menu.setIcon(new ImageIcon(MainWindow.class.getResource("/icon/管理(2).png")));menuBar.add(menu);JMenu menu_1 = new JMenu("设置");menu_1.setIcon(new ImageIcon(MainWindow.class.getResource("/icon/设置.png")));menuBar.add(menu_1);JMenuItem menuItem = new JMenuItem("主题");menuItem.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {new ThemeFrame().setVisible(true);}});menuItem.setIcon(new ImageIcon(MainWindow.class.getResource("/icon/界面设计.png")));menu_1.add(menuItem);JMenuItem menuItem_2 = new JMenuItem("网络配置");/*** * 网络配置单机事件* */menuItem_2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {new InternetConfigFrame().setVisible(true);}});menuItem_2.setIcon(new ImageIcon(MainWindow.class.getResource("/icon/网络.png")));menu_1.add(menuItem_2);JMenuItem menuItem_1 = new JMenuItem("退出系统");menuItem_1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {System.exit(0);}});menuItem_1.setIcon(new ImageIcon(MainWindow.class.getResource("/icon/退出.png")));menu_1.add(menuItem_1);JButton button = new JButton("刷新");button.setForeground(Color.BLACK);button.setBackground(UIManager.getColor("Button.background"));/*** * 刷新表格* */button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {try {fillTable(Dao.selectData());} catch (SQLException e) {e.printStackTrace();}}});button.setIcon(new ImageIcon(MainWindow.class.getResource("/icon/刷新.png")));menuBar.add(button);getContentPane().setLayout(new BorderLayout(0, 0));JPanel panel = new JPanel();FlowLayout flowLayout_1 = (FlowLayout) panel.getLayout();flowLayout_1.setVgap(70);flowLayout_1.setHgap(0);getContentPane().add(panel, BorderLayout.SOUTH);JPanel panel_1 = new JPanel();panel_1.setBorder(new TitledBorder(null, "\u8868\u5355\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null));getContentPane().add(panel_1, BorderLayout.WEST);JLabel stuText = new JLabel("学号:");stuField = new JTextField();/*** * 学号输入显示信息* */stuField.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {searchData();}});stuField.setColumns(10);JLabel nameText = new JLabel("姓名:");nameField = new JTextField();nameField.setColumns(10);JLabel ageText = new JLabel("年龄:");ageField = new JTextField();ageField.setColumns(10);JLabel label = new JLabel("性别:");radioMan = new JRadioButton("男");radioMan.setSelected(true);buttonGroup.add(radioMan);radioFemal = new JRadioButton("女");buttonGroup.add(radioFemal);JLabel label_1 = new JLabel("高数:");mathField = new JTextField();mathField.setColumns(10);JLabel lblJava = new JLabel("java:");javaField = new JTextField();javaField.setColumns(10);JLabel lblC = new JLabel("c语言:");cField = new JTextField();cField.setColumns(10);JLabel label_2 = new JLabel("英语:");englishField = new JTextField();englishField.setColumns(10);JButton button_1 = new JButton("修改");/*** * 修改信息事件* */button_1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {StudentData stu=new StudentData();if(StringUtil.isEmpy(stuField.getText())) {JOptionPane.showMessageDialog(null, "学号不能为空!");}else if(StringUtil.isEmpy(nameField.getText())) {JOptionPane.showMessageDialog(null, "姓名不能为空!");}else if(StringUtil.isEmpy(ageField.getText())) {JOptionPane.showMessageDialog(null, "年龄不能为空!");}else {stu.setNum(Integer.parseInt(stuField.getText()));stu.setName(nameField.getText());stu.setAge(Integer.parseInt(ageField.getText()));if(radioMan.isSelected()) {stu.setSex("男");}else {stu.setSex("女");}stu.setNum(Integer.parseInt(stuField.getText()));stu.setMath(Float.parseFloat(mathField.getText()));stu.setJava(Float.parseFloat(javaField.getText()));stu.setC(Float.parseFloat(cField.getText()));stu.setEnglish(Float.parseFloat(englishField.getText()));try {if(Dao.updateData(stu)>0) {JOptionPane.showMessageDialog(null, "修改成功!");fillTable(Dao.selectData());}else {JOptionPane.showMessageDialog(null, "修改失败!");}} catch (SQLException e) {e.printStackTrace();}}}});button_1.setIcon(new ImageIcon(MainWindow.class.getResource("/icon/修改(2).png")));JButton button_2 = new JButton("添加");/*** * 添加信息事件* */button_2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {if(StringUtil.isEmpy(stuField.getText())) {JOptionPane.showMessageDialog(null, "学号不能为空!");}else if(StringUtil.isEmpy(nameField.getText())) {JOptionPane.showMessageDialog(null, "姓名不能为空!");}else if(StringUtil.isEmpy(ageField.getText())) {JOptionPane.showMessageDialog(null, "年龄不能为空!");}else {StudentData stu=new StudentData();stu.setNum(Integer.parseInt(stuField.getText()));stu.setName(nameField.getText());stu.setAge(Integer.parseInt(ageField.getText()));if(radioMan.isSelected()) {stu.setSex("男");}else {stu.setSex("女");}stu.setMath(Float.parseFloat(mathField.getText()));stu.setJava(Float.parseFloat(javaField.getText()));stu.setC(Float.parseFloat(cField.getText()));stu.setEnglish(Float.parseFloat(englishField.getText()));try {if(JOptionPane.showConfirmDialog(null, "确定添加!")==0) {if(Dao.addData(stu)==1) {JOptionPane.showMessageDialog(null, "添加成功!");fillTable(Dao.selectData());//刷新表单}else {JOptionPane.showMessageDialog(null, "添加失败!");return;}}else {return;}} catch (SQLException e) {e.printStackTrace();}}}});button_2.setIcon(new ImageIcon(MainWindow.class.getResource("/icon/添加.png")));JButton button_3 = new JButton("删除");/*** * 删除鼠标单机事件* */button_3.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {StudentData stu=new StudentData();if(StringUtil.isEmpy(stuField.getText())) {JOptionPane.showMessageDialog(null, "请输入你要删除的学号!");}else {stu.setNum(Integer.parseInt(stuField.getText()));try {if(JOptionPane.showConfirmDialog(null, "确定要删除")==0) {if(Dao.deleteData(stu)>1) {JOptionPane.showMessageDialog(null, "删除成功!");clearText();fillTable(Dao.selectData());clearText();}else {JOptionPane.showMessageDialog(null, "删除失败!");}}else {return;}} catch (SQLException e) {e.printStackTrace();}}}});button_3.setIcon(new ImageIcon(MainWindow.class.getResource("/icon/删 除 (1).png")));JButton button_4 = new JButton("搜索");/*** * 搜索点击事件* */button_4.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {searchData();}});button_4.setIcon(new ImageIcon(MainWindow.class.getResource("/icon/查找(1).png")));JButton button_5 = new JButton("清空");/*** * 清空表单事件* */button_5.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {clearText();}});button_5.setIcon(new ImageIcon(MainWindow.class.getResource("/icon/清空.png")));GroupLayout gl_panel_1 = new GroupLayout(panel_1);gl_panel_1.setHorizontalGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING).addGroup(gl_panel_1.createSequentialGroup().addContainerGap(20, Short.MAX_VALUE).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addComponent(button_1).addGroup(gl_panel_1.createSequentialGroup().addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addComponent(lblJava).addComponent(lblC).addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING).addComponent(label_1).addComponent(label))).addComponent(label_2).addComponent(ageText).addComponent(nameText).addComponent(stuText)).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED).addComponent(javaField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGroup(gl_panel_1.createSequentialGroup().addGap(18).addComponent(radioMan).addGap(18).addComponent(radioFemal)).addGroup(gl_panel_1.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addComponent(englishField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(cField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(button_2, Alignment.TRAILING))).addGroup(gl_panel_1.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addComponent(stuField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(mathField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(nameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(ageField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))).addGroup(gl_panel_1.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addComponent(button_5).addGroup(gl_panel_1.createSequentialGroup().addComponent(button_3).addPreferredGap(ComponentPlacement.RELATED).addComponent(button_4))))).addGap(18)));gl_panel_1.setVerticalGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1.createSequentialGroup().addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(stuText).addComponent(stuField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(nameText).addComponent(nameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(ageText).addComponent(ageField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1.createSequentialGroup().addGap(8).addComponent(label)).addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(radioMan).addComponent(radioFemal))).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(label_1).addComponent(mathField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(18).addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(lblJava).addComponent(javaField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(18).addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(lblC).addComponent(cField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addComponent(label_2).addComponent(englishField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addComponent(button_1).addComponent(button_2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1.createSequentialGroup().addComponent(button_3).addPreferredGap(ComponentPlacement.RELATED, 9, Short.MAX_VALUE).addComponent(button_5)).addGroup(gl_panel_1.createSequentialGroup().addComponent(button_4).addContainerGap()))));panel_1.setLayout(gl_panel_1);JPanel panel_2 = new JPanel();FlowLayout flowLayout_2 = (FlowLayout) panel_2.getLayout();flowLayout_2.setHgap(0);flowLayout_2.setVgap(60);getContentPane().add(panel_2, BorderLayout.NORTH);JPanel panel_3 = new JPanel();FlowLayout flowLayout_3 = (FlowLayout) panel_3.getLayout();flowLayout_3.setHgap(120);flowLayout_3.setVgap(50);getContentPane().add(panel_3, BorderLayout.EAST);JScrollPane scrollPane = new JScrollPane();getContentPane().add(scrollPane, BorderLayout.CENTER);table = new JTable();/*** * 表单选中事件* */table.addMouseListener(new MouseAdapter() {@Overridepublic void mousePressed(MouseEvent e) {int row=table.getSelectedRow();stuField.setText(String.valueOf(table.getValueAt(row, 1)));nameField.setText((String) (table.getValueAt(row, 2)));ageField.setText(String.valueOf(table.getValueAt(row, 3)));String sex=(String) table.getValueAt(row, 4);if(sex.equals("男")) {radioMan.setSelected(true);}else {radioFemal.setSelected(true);}mathField.setText(String.valueOf(table.getValueAt(row, 5)));javaField.setText(String.valueOf(table.getValueAt(row, 6)));cField.setText(String.valueOf(table.getValueAt(row, 7)));englishField.setText(String.valueOf(table.getValueAt(row, 8)));}});/*** * * 菜单模型* * */table.setModel(new DefaultTableModel(new Object[][] {},new String[] {"\u5E8F\u53F7", "\u5B66\u53F7", "\u59D3\u540D", "\u5E74\u9F84", "\u6027\u522B", "\u9AD8\u6570", "JAVA", "C\u8BED\u8A00", "\u82F1\u8BED"}) {boolean[] columnEditables = new boolean[] {true, true, true, true, true, true, true, true, false};public boolean isCellEditable(int row, int column) {return columnEditables[column];package com.student.util;public class StringUtil {public static Boolean isEmpy(String str) {if(str==null||"".equals(str.trim())) {return true;}else {return false;}}public static Boolean notIsEmpy(String str) {if(str!=null&&!"".equals(str.trim())) {return true;}else {return false;}}}}});table.getColumnModel().getColumn(8).setResizable(false);try {this.fillTable(Dao.selectData());} catch (SQLException e1) {e1.printStackTrace();}scrollPane.setViewportView(table);}/*** * 填充表格方法* @param result* */public static  void fillTable( ResultSet result) {DefaultTableModel det=(DefaultTableModel) table.getModel();det.setRowCount(0);try {ResultSet rs=result;while(rs.next()) {Vector v=new Vector();v.add(rs.getInt(1));v.add(rs.getInt(2));v.add(rs.getString(3));v.add(rs.getString(4));v.add(rs.getString(5));v.add(rs.getString(6));v.add(rs.getString(7));v.add(rs.getString(8));v.add(rs.getString(9));det.addRow(v);}} catch (SQLException e) {e.printStackTrace();}}/*** * * 搜索数据* * */public void searchData() {if(StringUtil.isEmpy(stuField.getText())) {JOptionPane.showMessageDialog(null, "请输入学号!");return;}else {try {StudentData stu=new StudentData();stu.setNum(Integer.parseInt(stuField.getText()));ResultSet rs =Dao.search(stu);if(rs.next()) {fillTable(Dao.search(stu));stuField.setText(String.valueOf(rs.getInt(2)));nameField.setText(rs.getString(3));ageField.setText(String.valueOf(rs.getInt(4)));if(rs.getString(5).equals("男")) {radioMan.setSelected(true);}else {radioFemal.setSelected(true);}mathField.setText(String.valueOf(rs.getFloat(6)));javaField.setText(String.valueOf(rs.getFloat(7)));cField.setText(String.valueOf(rs.getFloat(8)));englishField.setText(String.valueOf(rs.getFloat(9)));return;}else {JOptionPane.showMessageDialog(null, "没有此学生或学号输入有误");return;}} catch (SQLException e) {e.printStackTrace();}}}/*** * 文本框制空*/public void clearText() {stuField.setText("");nameField.setText("");ageField.setText("");radioMan.setSelected(true);mathField.setText("");javaField.setText("");cField.setText("");englishField.setText("");}
}

字符串判空工具代码

package com.student.util;public class StringUtil {public static Boolean isEmpy(String str) {if(str==null||"".equals(str.trim())) {return true;}else {return false;}}public static Boolean notIsEmpy(String str) {if(str!=null&&!"".equals(str.trim())) {return true;}else {return false;}}}

学生信息模型

package com.student.modal;public class StudentData {private int id;private int num;private String name;private String sex;private int age;private float math;private float java;private float c;private float english;public int getId() {return id;}public void setId(int id) {this.id = id;}public int getNum() {return num;}public void setNum(int num) {this.num = num;}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 float getMath() {return math;}public void setMath(float math) {this.math = math;}public float getJava() {return java;}public void setJava(float java) {this.java = java;}public float getC() {return c;}public void setC(float c) {this.c = c;}public float getEnglish() {return english;}public void setEnglish(float english) {this.english = english;}}

用户登陆信息模型

package com.student.modal;public class User {private double user;private String password;public Double getUser() {return user;}public void setUser(Double user) {this.user = user;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}

界面修改模型

package com.student.modal;public class ThemeValue {private int X1;private int Y1;private int X2;private int Y2;private String themeTitle;private String backgroundColor;public int getX1() {return X1;}public void setX1(int x1) {X1 = x1;}public int getY1() {return Y1;}public void setY1(int y1) {Y1 = y1;}public int getX2() {return X2;}public void setX2(int x2) {X2 = x2;}public int getY2() {return Y2;}public void setY2(int y2) {Y2 = y2;}public String getThemeTitle() {return themeTitle;}public void setThemeTitle(String themeTitle) {this.themeTitle = themeTitle;}public String getBackgroundColor() {return backgroundColor;}public void setBackgroundColor(String backgroundColor) {this.backgroundColor = backgroundColor;}}

数据库后台实现

package com.student.Data;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;import com.mysql.jdbc.PreparedStatement;
import com.student.modal.StudentData;
import com.student.modal.User;public class Dao {/*** 变量定义*/private static Connection conn=null;private static String user="root";private static String password="root";private static String DRIVER="com.mysql.jdbc.Driver";private static String dataUrl="jdbc:mysql://localhost:3306/StudentSystem?useUnicode=true&characterEncoding=utf-8";/*** 加载驱动* 获取数据库连接*/public Dao() {try {Class.forName(DRIVER);if(conn==null) {conn=DriverManager.getConnection(dataUrl,user,password);}else {return;}} catch (Exception e) {e.printStackTrace();}}/*** * 关闭数据库*/public static void close() {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}public static PreparedStatement prepareStatement(String sql) throws SQLException {PreparedStatement pstmt = null;new Dao();return pstmt = (PreparedStatement) conn.prepareStatement(sql);}/*** 用户登陆检验后台* @param user* @return* @throws SQLException*/public static User checkLogin(User user) throws SQLException {User reUser=null;String sql =  "select *  from user where user=? and password=?";PreparedStatement pstmt=Dao.prepareStatement(sql);pstmt.setDouble(1, user.getUser());pstmt.setString(2, user.getPassword());ResultSet rs=pstmt.executeQuery();if(rs.next()){reUser=new User();reUser.setUser(rs.getDouble(1));reUser.setPassword(rs.getString(2));}pstmt.close();return reUser;}/*** 搜索数据后台* @return* @throws SQLException*/public static ResultSet selectData() throws SQLException {String sql="select * from StudentData";PreparedStatement pstmt=Dao.prepareStatement(sql);return pstmt.executeQuery();}/*** * 删除数据后台* @param stu* @return* @throws SQLException */public static int deleteData(StudentData stu) throws SQLException{String sql="delete from StudentData where num=?";int i = 0; PreparedStatement pst = Dao.prepareStatement(sql);pst.setInt(1, stu.getNum());i=pst.executeUpdate(); return i;}/*** 更新数据后台* @param * @return* @throws SQLException*/public static int updateData(StudentData stu) throws SQLException {String sql="update   StudentData set name=?,age=?,sex=?,math=?,java=?,c=?,english=? where num=?";PreparedStatement pst=Dao.prepareStatement(sql);pst.setString(1, stu.getName());pst.setInt(2, stu.getAge());pst.setString(3, stu.getSex());pst.setFloat(4, stu.getMath());pst.setFloat(5, stu.getJava());pst.setFloat(6,stu.getC()) ;pst.setFloat(7, stu.getEnglish());pst.setInt(8, stu.getNum());return pst.executeUpdate();}/*** 添加数据后台* @param stu* @return* @throws SQLException*/public static  int addData(StudentData stu) throws SQLException {String sql="insert into StudentData values(null,?,?,?,?,?,?,?,?)";PreparedStatement pst=Dao.prepareStatement(sql);pst.setInt(1, stu.getNum());pst.setString(2, stu.getName());pst.setInt(3, stu.getAge());pst.setString(4, stu.getSex());pst.setFloat(5, stu.getMath());pst.setFloat(6, stu.getJava());pst.setFloat(7, stu.getC());pst.setFloat(8, stu.getEnglish());return pst.executeUpdate();}public static ResultSet search(StudentData stu) throws SQLException {String sql="select * from StudentData where num=?";PreparedStatement pstmt=Dao.prepareStatement(sql);pstmt.setInt(1, stu.getNum());return pstmt.executeQuery();}}

程序中可能有些需要改进的地方,如果又发现,可以联系QQ:873634918,或者发送电子邮件到873634918@qq.com,小白菜会及时纠正错误,这个项目主要是入门swing(GUI图新化编程)写的一个入门项目,只实现了增删改查等操作,还有很多功能有待实现。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/517590.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

干货 | 大白话彻底搞懂 HBase RowKey 详细设计

作者 | 且听风吟责编 | Carol封图 | CSDN 付费下载于视觉中国前言RowKey作为HBase的核心知识点,RowKey设计会影响到数据在HBase中的分布,还会影响我们查询效率,所以RowKey的设计质量决定了HBase的质量。是咱们大数据从业者必知必会的&#xf…

Knative 实战:如何在 Knative 中配置自定义域名及路由规则

目前 Knative 中默认支持是基于域名的转发,但域名默认格式是:"{{.Name}}.{{.Namespace}}.{{.Domain}}"(这个可以在 config-network 配置)。但对于用户来说并不能指定全域名。 另外一个问题就是基于Path 转发的能力&…

混合云模式下 MaxCompute + Hadoop 混搭大数据架构实践

摘要:2019杭州云栖大会大数据企业级服务专场,由斗鱼大数据高级专家张龙带来以 “混合云模式下 MaxComputeHadoop 混搭大数据架构实践” 为题的演讲。本文讲述了从 Apache Hadoop 阶段到 Cloudera CDH 阶段斗鱼大数据架构的发展历程。提出了上云过程中斗鱼…

mybatisplus 一次性执行多条SQL语句

文章目录一、Mysql数据库1. Url2. xml映射文件二、Oracle数据库2.1. 关键点2.2. xml映射文件一、Mysql数据库 关键点:在url后面添加&allowMultiQueriestrue,sql后面添加分号; 1. Url 案例: url: jdbc:mysql://localhost:3306/afsdb?…

没错!Python程序员正在消失,HR:你才知道?

Python为什么这么火?学了Python能干什么?Python程序员有前途吗?几乎所有人脑子里都有这个疑问,感觉现在铺天盖地都是Python的消息,就连刷抖音都能刷到Python,Python已经火出圈了!Python为什么这…

swing中模态对话框(setModal(true))和显示对话框(setVisible(true))的编写顺序

今天给大家分享一个鄙人在编程中总结出的一个易错点和最容易让人感到困惑的一个知识点: 当你要从一个窗体跳转到另一个窗体,你把跳转目标的窗体设成模态对话框,设计成模态对话框就是禁止父窗体与子窗体之间操作,简单说就是当调用子…

Service Mesh 初体验

前言 计算机软件技术发展到现在,软件架构的演进无不朝着让开发者能够更加轻松快捷地构建大型复杂应用的方向发展。容器技术最初是为了解决运行环境的不一致问题而产生的,随着不断地发展,围绕容器技术衍生出来越来越多的新方向。 最近几年&a…

mybatisplus 一次性执行多条SQL语句插入(Mysql篇)

文章目录一、数据库部分1. 创建数据库2. 初始化表结构二、代码部分2.1. controller2.2. mapper接口2.3. 映射文件2.4. 参数封装三、测试验证3.1. 发起请求3.2. 查看数据库3.3. 配置文件部分一、数据库部分 1. 创建数据库 创建more-insert 2. 初始化表结构 -- 一次性插入多张…

带领国产数据库走向世界,POLARDB底层逻辑是什么?

POLARDB 是阿里云自主研发的下一代云原生分布式数据库,100%兼容MySQL、PostgreSQL等开源数据库,高度兼容Oracle语法,使用RDS服务的客户不需要修改应用代码,可以一键迁移到POLARDB,体验更大的容量,更高的性能…

基于java+swing+mysql+JFeeChart的企业人力资源管理系统(1)

文章目录一,前言二,项目运行图(1)主界面(管理员界面)(2)员工资料运行图(3)全部员工查看运行图(4)部门管理运行图(5&#x…

十年架构师:我是这样手写Spring的,用300行代码体现优雅之道

起源Spring作为一个开源框架,于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作《Expert One-On-One J2EE Development and Design》中阐述的部分理念和原型衍生而来。它是为了解决企业应用开发的复杂性而创建的。框架的主要优势之一就是…

深度 | 打败围棋冠军后,机器智能下一步能战胜黑客吗?

阿里妹导读:从深蓝战胜象棋冠军到AlphaGo战胜围棋冠军,每一次机器智能在特定领域战胜人类,都会引发整个社会的广泛关注。洞察了棋类博弈真相的机器智能,接下来能洞察网络安全的真相并且在黑客博弈中战胜人类吗?在机器智…

mybatisplus 一次性执行多条SQL语句插入(Oracle篇)

文章目录一、数据库部分1. 创建数据库2. 初始化表结构二、代码部分2.1. controller2.2. mapper接口2.3. 映射文件2.4. 参数封装三、测试验证3.1. 发起请求3.2. 查看数据库3.3. 配置文件部分一、数据库部分 1. 创建数据库 创建more-insert 2. 初始化表结构 -- 一次性插入多张…

从310到蚂蚁森林,蚂蚁金服在线图计算的创新与实践

蚂蚁金服过去十五年,重塑支付改变生活,为全球超过十二亿人提供服务,这些背后离不开技术的支撑。在 2019 杭州云栖大会上,蚂蚁金服将十五年来的技术沉淀,以及面向未来的金融技术创新和参会者分享。我们将其中的优秀演讲…

Seata 与 Nacos注册中心整合实现集群环境搭建_02

接上一篇:Seata 单机环境搭建_01 文章目录一、整体架构二、安装步骤2.1. 创建数据库2.2. 初始化表结构2.3. 修改配置文件2.4. 调整数据库驱动2.5. 修改配置中心三、 启动和验证3.1. 启动nacos3.2. 启动TC Server3.3. 验证高可用一、整体架构 我们来学习部署集群 Se…

趣谈程序员真香定律:源码即设计

来源 | 码砖杂役责编 | Carol封图 | CSDN 付费下载自视觉中国我们经常谈论架构,讨论设计,却甚少关注实现和代码本身,架构和设计固然重要,但要说代码本身不重要,我不同意,Robert C.Martin大叔也不同意&#…

Nacos 1.1.4 发布,业界率先支持 Istio MCP 协议

Nacos是阿里巴巴开源的服务发现与配置管理项目,本次发布的1.1.4版本,主要带来的是与Istio的对接功能,使用的是Istio最新的MCP协议。本文将介绍包括这个功能在内的新版本发布的功能。 升级指南 服务端 0.8.0及以上版本: 解压安…

Seata 与 Nacos Config配置中心整合_03

前言:之前我们只将nacos注册中心和seata进行了整合,如果需要实现完整的功能还需要与nacos的配置中心进行整合。 文章目录一、配置管理1. 创建文件config.txt2. 创建nacos-config.sh3. 配置导入nacos配置中心4. 配置验证一、配置管理 1. 创建文件config.…

牛!阿里云位居中国金融云市场第一

近日,全球权威市场研究机构IDC发布《中国金融云解决方案市场跟踪研究,2019H1》报告:阿里云位居中国金融云解决方案市场第一,并成为市场份额突破两位数的唯一厂商,同比增长超过90%。 IDC统计数据显示,阿里云…

抖音、快手和直播行业的火爆究竟给了谁机会?

经常收到一些CSDN小伙伴的留言,反馈如下这样的困惑“短视频这么火爆,我该学些什么技术才能入行?”“我想从事音视频开发,该如何入门和进阶?真的像坊间传闻的那么难吗?”音视频的开发前景做一个不恰当的比喻…