Java實(shí)訓(xùn)(GUI和mysql8.0)——可視化學(xué)生管理系統(tǒng)

記錄下這學(xué)期java實(shí)訓(xùn)(懶得保存了,干脆寫成文章)
鏈接:https://pan.baidu.com/s/1Tm2diXuhxDx6C7rCOJ0ARA
提取碼:eada

里面有源碼工程文件和相關(guān)工具
mysql8.0官網(wǎng)下載


主窗口

package 學(xué)籍管理系統(tǒng)視窗;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.CardLayout;
import java.awt.Toolkit;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;

import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;
import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;

public class 主窗口 extends JFrame {
    

    private JPanel contentPane;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    主窗口 frame = new 主窗口();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     * @throws SQLException 
     */
    public 主窗口() throws SQLException {
        //this.setLocationRelativeTo(null);
        setBounds(100, 100, 800, 500);
        this.setLocationRelativeTo(null);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        CardLayout card=new CardLayout();
        contentPane.setLayout(card);
        歡迎面板 歡迎面板=new 歡迎面板();
        contentPane.add("0",歡迎面板);
        修改面板 修改面板=new 修改面板();
        contentPane.add("2",修改面板);
        錄入面板 錄入面板=new 錄入面板();
        contentPane.add("1",錄入面板);
        刪除面板 刪除面板=new 刪除面板();
        contentPane.add("3",刪除面板);
        查詢面板  查詢面板=new 查詢面板();
        contentPane.add("4",查詢面板);
        查看面板  查看面板=new 查看面板();
        contentPane.add("5",查看面板);
        
        
        setTitle("\u5E7F\u5DDE\u822A\u6D77\u5B66\u9662\u5B66\u751F\u7BA1\u7406\u7CFB\u7EDF");
        setIconImage(Toolkit.getDefaultToolkit().getImage("E:\\eclipse64\u4F4D\\workplace\\\u5B66\u7C4D\u7BA1\u7406\u7CFB\u7EDF\u89C6\u7A97\\image\\668eca61e8886291e5af08b33983448e.jpg"));
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        
        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);
        
        JMenu menu = new JMenu("\u64CD\u4F5C\u83DC\u5355");
        menu.setIcon(new ImageIcon("E:\\eclipse64\u4F4D\\workplace\\\u5B66\u7C4D\u7BA1\u7406\u7CFB\u7EDF\u89C6\u7A97\\image\\\u622A\u56FE20190624192426.png"));
        
        menuBar.add(menu);
        
        JMenuItem menuItem = new JMenuItem("\u5F55\u5165\u5B66\u751F\u4FE1\u606F");
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.ALT_MASK));
        menuItem.setIcon(new ImageIcon("E:\\eclipse64\u4F4D\\workplace\\\u5B66\u7C4D\u7BA1\u7406\u7CFB\u7EDF\u89C6\u7A97\\image\\\u622A\u56FE20190624192512.png"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                card.show(contentPane, "1");
            }
        });
        
        menu.add(menuItem);
        
        JMenuItem menuItem_1 = new JMenuItem("\u4FEE\u6539\u5B66\u751F\u4FE1\u606F");
        menuItem_1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.ALT_MASK));
        menuItem_1.setIcon(new ImageIcon("E:\\eclipse64\u4F4D\\workplace\\\u5B66\u7C4D\u7BA1\u7406\u7CFB\u7EDF\u89C6\u7A97\\image\\\u622A\u56FE20190624192548.png"));
        menuItem_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                card.show(contentPane, "2");
            }
        });
        
        menu.add(menuItem_1);
        
        JMenuItem menuItem_2 = new JMenuItem("\u5220\u9664\u5B66\u751F\u4FE1\u606F");
        menuItem_2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK));
        menuItem_2.setIcon(new ImageIcon("E:\\eclipse64\u4F4D\\workplace\\\u5B66\u7C4D\u7BA1\u7406\u7CFB\u7EDF\u89C6\u7A97\\image\\\u622A\u56FE20190624192731.png"));
        menuItem_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                card.show(contentPane, "3");
            }
        });
        menu.add(menuItem_2);
        
        JMenuItem menuItem_3 = new JMenuItem("\u67E5\u8BE2\u5B66\u751F\u4FE1\u606F");
        menuItem_3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK));
        menuItem_3.setIcon(new ImageIcon("E:\\eclipse64\u4F4D\\workplace\\\u5B66\u7C4D\u7BA1\u7406\u7CFB\u7EDF\u89C6\u7A97\\image\\\u622A\u56FE20190624192757.png"));
        menuItem_3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                card.show(contentPane, "4");
            }
        });
        menu.add(menuItem_3);
        
        JMenuItem menuItem_4 = new JMenuItem("\u663E\u793A\u6240\u6709\u4FE1\u606F");
        menuItem_4.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_MASK));
        menuItem_4.setIcon(new ImageIcon("E:\\eclipse64\u4F4D\\workplace\\\u5B66\u7C4D\u7BA1\u7406\u7CFB\u7EDF\u89C6\u7A97\\image\\\u622A\u56FE20190624192820.png"));
        menuItem_4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                card.show(contentPane, "5");
            }
        });
        menu.add(menuItem_4);
    
        
    
        
        
    }
}

歡迎面板

package 學(xué)籍管理系統(tǒng)視窗;

import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Font;

public class 歡迎面板 extends JPanel {

    /**
     * Create the panel.
     */
    public 歡迎面板() {
        setBackground(Color.CYAN);
        setLayout(null);
        
        JLabel lblNewLabel = new JLabel("\u6B22\u8FCE\u4F7F\u7528\u5E7F\u5DDE\u822A\u6D77\u5B66\u9662\u5B66\u751F\u7BA1\u7406\u7CFB\u7EDF");
        lblNewLabel.setFont(new Font("宋體", Font.PLAIN, 24));
        lblNewLabel.setBounds(34, 90, 387, 62);
        add(lblNewLabel);
        
        JLabel label = new JLabel("\u8BF7\u4F60\u6309\u5DE6\u4E0A\u89D2\u83DC\u5355\u680F\u63D0\u793A\u64CD\u4F5C");
        label.setBounds(100, 178, 233, 18);
        add(label);
        

    }
}

錄入面板

package 學(xué)籍管理系統(tǒng)視窗;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.SQLException;

import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;


import 數(shù)據(jù)庫(kù).Test;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class 錄入面板 extends JPanel {
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    
    private JLabel lblNewLabel;


    /**
     * Create the panel.
     */
    public 錄入面板() {
        setLayout(null);
         lblNewLabel = new JLabel("\u5B66\u53F7");
        lblNewLabel.setBounds(72, 55, 30, 18);
        add(lblNewLabel);
        
        JLabel label = new JLabel("\u59D3\u540D");
        label.setBounds(72, 24, 30, 18);
        add(label);
        
        textField = new JTextField("請(qǐng)輸入學(xué)號(hào)");
        textField.setBounds(116, 52, 130, 24);
        textField.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                textField.setText("");
            }
        });
        add(textField);
        textField.setColumns(10);
        
        textField_1 = new JTextField("請(qǐng)輸入姓名");
        textField_1.setBounds(116, 21, 130, 24);
        textField_1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                textField_1.setText("");
            }
        });
        add(textField_1);
        textField_1.setColumns(10);
        
        JLabel label_1 = new JLabel("\u6027\u522B");
        label_1.setBounds(72, 89, 30, 18);
    add(label_1);
        
        
        JRadioButton radioButton = new JRadioButton("\u7537");
        radioButton.setBounds(126, 85, 43, 27);
        add(radioButton);
        
        JRadioButton radioButton_1 = new JRadioButton("\u5973");
        radioButton_1.setBounds(175, 85, 55, 27);
        add(radioButton_1);
        
        //創(chuàng)建ButtonGroup對(duì)象
                ButtonGroup btgSex = new ButtonGroup();
                btgSex.add(radioButton);
                btgSex.add(radioButton_1);
        
        JLabel label_2 = new JLabel("\u5B66\u9662");
        label_2.setBounds(72, 120, 30, 18);
        add(label_2);
        
        ComboBoxModel aModel1=new  DefaultComboBoxModel(new String[]{"航海技術(shù)","航海技術(shù)1","航海技術(shù)2"});
         ComboBoxModel aModel2=new  DefaultComboBoxModel(new String[]{"輪機(jī)工程學(xué)","輪機(jī)工程學(xué)1","輪機(jī)工程學(xué)2"});
         ComboBoxModel aModel3=new  DefaultComboBoxModel(new String[]{"計(jì)算機(jī)科學(xué)與技術(shù)","電子商務(wù)(本科)","軟件技術(shù)","計(jì)算機(jī)應(yīng)用技術(shù)","電子商務(wù)"});
         ComboBoxModel aModel4=new  DefaultComboBoxModel(new String[]{"英語(yǔ)","日語(yǔ)","外語(yǔ)學(xué)"});
            JComboBox comboBox_1 = new JComboBox();
            comboBox_1.setBounds(110, 151, 168, 24);
            comboBox_1.setToolTipText("");
            add(comboBox_1);
            
            
         JComboBox comboBox = new JComboBox();
         comboBox.setBounds(110, 117, 164, 24);
        comboBox.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if(e.getStateChange()==ItemEvent.SELECTED)
                {
                 int a=comboBox.getSelectedIndex();
                 if(a==0)
                 {
                     comboBox_1.setModel(aModel1);
                     comboBox_1.setSelectedIndex(-1);
                 
                 }
                 else if(a==1)
                 {
                     comboBox_1.setModel(aModel2);
                     comboBox_1.setSelectedIndex(-1);
                  
                 }
                 else if(a==2)
                 {
                     comboBox_1.setModel(aModel3);
                     comboBox_1.setSelectedIndex(-1);
                 }
                 else if(a==3)
                 {
                     comboBox_1.setModel(aModel4);
                     comboBox_1.setSelectedIndex(-1);
                 }
                 
                }
            }
        });
        comboBox.setModel(new DefaultComboBoxModel(new String[] {"海運(yùn)學(xué)院", "輪機(jī)工程學(xué)院", "信息與通信工程學(xué)院", "外語(yǔ)學(xué)院"}));
        comboBox.setSelectedIndex(-1);
        add(comboBox);
        
        JButton button = new JButton("\u5F55\u5165");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
                String sex="";
                if(radioButton.isSelected()) {
                    sex=radioButton.getText();
                }else {
                    sex=radioButton_1.getText();
                }
            
                if(textField_1.getText().equals("")||textField_1.getText().equals("請(qǐng)輸入姓名")) {
                    JOptionPane.showMessageDialog(null,"請(qǐng)輸入姓名","錯(cuò)誤",JOptionPane.ERROR_MESSAGE);
                    return;
                }
                
                if(textField.getText().equals("")||textField.getText().equals("請(qǐng)輸入學(xué)號(hào)")) {
                    JOptionPane.showMessageDialog(null,"請(qǐng)輸入學(xué)號(hào)","錯(cuò)誤",JOptionPane.ERROR_MESSAGE);
                    return;
                }
                
                if(comboBox.getSelectedIndex()==-1) {
                    JOptionPane.showMessageDialog(null,"請(qǐng)選擇學(xué)院","錯(cuò)誤",JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if(comboBox_1.getSelectedIndex()==-1) {
                    JOptionPane.showMessageDialog(null,"請(qǐng)選擇專業(yè)","錯(cuò)誤",JOptionPane.ERROR_MESSAGE);
                    return;
                }
                
                if(textField_2.getText().equals("")) {
                    JOptionPane.showMessageDialog(null,"請(qǐng)輸入班級(jí)","錯(cuò)誤",JOptionPane.ERROR_MESSAGE);
                    return;
                }
                
                
                //保存數(shù)據(jù)
                String sno=textField.getText();
                String name=textField_1.getText();
                String ssex;
                if(radioButton.isSelected()) {
                     ssex="男";
                }else
                     ssex="女";
                
                String department=comboBox.getSelectedItem().toString();
                String major=comboBox_1.getSelectedItem().toString();
                String myclass=textField_2.getText();
                //調(diào)用自己鏈接數(shù)據(jù)庫(kù)操作方法test
                Connection sin=Test.getconnectin();
                boolean flag;
                flag=Test.chongfu(sin,sno);
                System.out.println(flag);
                if(flag==false) {
                Object str[]={sno,name,ssex,department,major,myclass};
                
                Test.insert(sin, str);
                JOptionPane.showMessageDialog(null,"錄入成功","提示",JOptionPane.INFORMATION_MESSAGE);
                radioButton.setSelected(false);
                radioButton_1.setSelected(false);
                textField.setText("請(qǐng)輸入學(xué)號(hào)");
                textField_1.setText("請(qǐng)輸入姓名");
                textField_2.setText("");
                comboBox.setSelectedIndex(-1);
                comboBox_1.setSelectedIndex(-1);
                }
                else
                    JOptionPane.showMessageDialog(null,"失敗,學(xué)號(hào)重復(fù)","提示",JOptionPane.INFORMATION_MESSAGE);
                
                
            
            }
        });
        button.setBounds(203, 232, 63, 27);
        add(button);
        
        JButton button_1 = new JButton("\u91CD\u7F6E");
        button_1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                radioButton.setSelected(false);
                radioButton_1.setSelected(false);
                textField.setText("請(qǐng)輸入學(xué)號(hào)");
                textField_1.setText("請(qǐng)輸入姓名");
                textField_2.setText("");
                comboBox.setSelectedIndex(-1);
                comboBox_1.setSelectedIndex(-1);
                JOptionPane.showMessageDialog(null,"重置成功","提示",JOptionPane.INFORMATION_MESSAGE);
            
            }
        });
        button_1.setBounds(106, 232, 63, 27);
        add(button_1);
        
        JLabel label_3 = new JLabel("\u4E13\u4E1A");
        label_3.setBounds(72, 154, 30, 18);
        add(label_3);
        
        JLabel label_4 = new JLabel("\u73ED\u7EA7");
        label_4.setBounds(72, 191, 30, 18);
        add(label_4);
        
        textField_2 = new JTextField();
        textField_2.setBounds(110, 188, 164, 24);
        add(textField_2);
        textField_2.setColumns(10);
        
    }

    }
        


修改面板

package 學(xué)籍管理系統(tǒng)視窗;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JTextField;


import 數(shù)據(jù)庫(kù).Test;

import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class 修改面板 extends JPanel {
    
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;

    /**
     * Create the panel.
     */
    public 修改面板() {
        setLayout(null);
        
        JLabel label = new JLabel("\u8F93\u5165\u8981\u4FEE\u6539\u4FE1\u606F\u7684\u5B66\u53F7\uFF1A");
        label.setFont(new Font("宋體", Font.PLAIN, 16));
        label.setBounds(42, 18, 177, 18);
        add(label);
        
        textField = new JTextField();
        textField.setBounds(213, 15, 144, 24);
        add(textField);
        textField.setColumns(10);
        
        
        
        
        JLabel label_1 = new JLabel("\uFF08\u65B0\uFF09\u59D3\u540D\uFF1A");
        label_1.setBounds(42, 76, 120, 18);
        add(label_1);
        
        textField_1 = new JTextField();
        textField_1.setBounds(133, 73, 120, 24);
        add(textField_1);
        textField_1.setColumns(10);
        
        JRadioButton radioButton = new JRadioButton("\u7537");
        radioButton.setBounds(107, 119, 51, 27);
        add(radioButton);
        
        JRadioButton radioButton_1 = new JRadioButton("\u5973");
        radioButton_1.setBounds(168, 119, 51, 27);
        add(radioButton_1);
        ButtonGroup btgSex = new ButtonGroup();
        btgSex.add(radioButton);
        btgSex.add(radioButton_1);
        
        
        ComboBoxModel aModel1=new  DefaultComboBoxModel(new String[]{"航海技術(shù)","航海技術(shù)1","航海技術(shù)2"});
         ComboBoxModel aModel2=new  DefaultComboBoxModel(new String[]{"輪機(jī)工程學(xué)","輪機(jī)工程學(xué)1","輪機(jī)工程學(xué)2"});
         ComboBoxModel aModel3=new  DefaultComboBoxModel(new String[]{"計(jì)算機(jī)科學(xué)與技術(shù)","電子商務(wù)(本科)","軟件技術(shù)","計(jì)算機(jī)應(yīng)用技術(shù)","電子商務(wù)"});
         ComboBoxModel aModel4=new  DefaultComboBoxModel(new String[]{"英語(yǔ)","日語(yǔ)","外語(yǔ)學(xué)"});
            JComboBox comboBox_1 = new JComboBox();
            comboBox_1.setToolTipText("");
            comboBox_1.setBounds(133, 207, 185, 24);
            this.add(comboBox_1);
            
            
         JComboBox comboBox = new JComboBox();
        comboBox.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if(e.getStateChange()==ItemEvent.SELECTED)
                {
                 int a=comboBox.getSelectedIndex();
                 if(a==0)
                 {
                     comboBox_1.setModel(aModel1);
                     comboBox_1.setSelectedIndex(-1);
                 
                 }
                 else if(a==1)
                 {
                     comboBox_1.setModel(aModel2);
                     comboBox_1.setSelectedIndex(-1);
                  
                 }
                 else if(a==2)
                 {
                     comboBox_1.setModel(aModel3);
                     comboBox_1.setSelectedIndex(-1);
                 }
                 else if(a==3)
                 {
                     comboBox_1.setModel(aModel4);
                     comboBox_1.setSelectedIndex(-1);
                 }
                 
                }
            }
        });
        comboBox.setModel(new DefaultComboBoxModel(new String[] {"\u6D77\u8FD0\u5B66\u9662", "\u8F6E\u673A\u5DE5\u7A0B\u5B66\u9662", "\u4FE1\u606F\u4E0E\u901A\u4FE1\u5DE5\u7A0B\u5B66\u9662", "\u5916\u8BED\u5B66\u9662"}));
        comboBox.setSelectedIndex(-1);
        comboBox.setBounds(133, 167, 182, 24);
        this.add(comboBox);
        
        JLabel lblNewLabel = new JLabel("\u65B0\u5B66\u9662\uFF1A");
        lblNewLabel.setBounds(72, 169, 71, 18);
        add(lblNewLabel);
        
        JLabel label_2 = new JLabel("\u65B0\u4E13\u4E1A\uFF1A");
        label_2.setBounds(70, 210, 72, 18);
        add(label_2);
        
        JLabel label_3 = new JLabel("\u65B0 \u73ED\u7EA7");
        label_3.setBounds(72, 247, 72, 18);
        add(label_3);
        
        textField_2 = new JTextField();
        textField_2.setBounds(133, 244, 185, 24);
        add(textField_2);
        textField_2.setColumns(10);
        
        JButton button = new JButton("\u4FEE\u6539");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
                
                
                String sno=textField.getText();
                String name=textField_1.getText();
                String ssex;
                if(radioButton.isSelected()) {
                     ssex="男";
                }else
                     ssex="女";
                
                String department=comboBox.getSelectedItem().toString();
                String major=comboBox_1.getSelectedItem().toString();
                String myclass=textField_2.getText();
                //調(diào)用自己鏈接數(shù)據(jù)庫(kù)操作方法test
                Object str[]={sno,name,ssex,department,major,myclass};
                Connection sin=Test.getconnectin();
                Test.update(sin, str);
                radioButton.setSelected(false);
                radioButton_1.setSelected(false);
                textField.setText("");
                textField_1.setText("");
                textField_2.setText("");
                comboBox.setSelectedIndex(-1);
                comboBox_1.setSelectedIndex(-1);
                JOptionPane.showMessageDialog(null,"修改成功","提示",JOptionPane.NO_OPTION );
                
                
            }
        });
        button.setBounds(82, 282, 114, 27);
        add(button);
        
        JButton button_1 = new JButton("\u91CD\u7F6E");
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                radioButton.setSelected(false);
                radioButton_1.setSelected(false);
                textField.setText("");
                textField_1.setText("");
                textField_2.setText("");
                comboBox.setSelectedIndex(-1);
                comboBox_1.setSelectedIndex(-1);
                JOptionPane.showMessageDialog(null,"重置成功!","信息",JOptionPane.INFORMATION_MESSAGE );
            }
        });
        button_1.setBounds(204, 282, 114, 27);
        add(button_1);
        
        JButton btnNewButton = new JButton("\u67E5\u8BE2");
        btnNewButton.setToolTipText("");
        btnNewButton.setBounds(364, 15, 79, 27);
        add(btnNewButton);
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
                 Connection sin=Test.getconnectin();
                    String sno=textField.getText();
                    ResultSet rs=null;
                    PreparedStatement stmt=null;
                    boolean flag=false;
                    try {
                        //牛逼查找
                         stmt=sin.prepareStatement("select * from student where sno=?");
                        stmt.setObject(1,sno);
                        rs=stmt.executeQuery();
                        while(rs.next()){
                        String msg=rs.getString("sno")+"\n"+rs.getString("name")+"\n"+rs.getString("sex")+"\n"+rs.getString("department")+"\n"+rs.getString("subject")+"\n"+rs.getString("myclass")+"\n";
                        //JOptionPane.showMessageDialog(null,msg,"查詢結(jié)果:",JOptionPane.NO_OPTION );
                        flag=true;
                        //修改
                        textField_1.setText(rs.getString("name"));
                        String ssex=null;
                        ssex=rs.getString("sex");
                        if(ssex.equalsIgnoreCase("男")) {
                            radioButton.setSelected(true);

                        }else {
                            radioButton_1.setSelected(true);
                        }
                        textField_2.setText(rs.getString("myclass"));
                        comboBox.setSelectedItem(rs.getString("department"));
                        comboBox_1.setSelectedItem(rs.getString("subject"));
                        
                        }
                        if(flag==false) {
                            radioButton.setSelected(false);
                            radioButton_1.setSelected(false);
                            
                            textField_1.setText("");
                            textField_2.setText("");
                            comboBox.setSelectedIndex(-1);
                            comboBox_1.setSelectedIndex(-1);
                            JOptionPane.showMessageDialog(null,"查無(wú)此人","查詢結(jié)果",JOptionPane.NO_OPTION );
                            
                            
                        }
                            stmt.close();//關(guān)閉數(shù)據(jù)庫(kù)
                            sin.close();
                        } catch (SQLException h) {
                            // TODO Auto-generated catch block
                            h.printStackTrace();
                        }
                    }
            
        });

    }
}

查詢面板

package 學(xué)籍管理系統(tǒng)視窗;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;


import 數(shù)據(jù)庫(kù).Test;

import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;

public class 查詢面板 extends JPanel {
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JTextField textField_4;
    private JTextField textField_5;

    /**
     * Create the panel.
     */
    public 查詢面板() {
        setLayout(null);
        
        JLabel label = new JLabel("\u8F93\u5165\u8981\u67E5\u8BE2\u4FE1\u606F\u7684\u5B66\u53F7\uFF1A");
        label.setBounds(37, 22, 189, 18);
        add(label);
        
        textField = new JTextField();
        textField.setBounds(201, 19, 154, 24);
        add(textField);
        textField.setColumns(10);
        
        JLabel label_1 = new JLabel("\u59D3\u540D");
        label_1.setBounds(72, 60, 40, 18);
        add(label_1);
        
        textField_1 = new JTextField();
        textField_1.setEnabled(false);
        textField_1.setBounds(112, 60, 150, 24);
        add(textField_1);
        textField_1.setColumns(10);
        
        JLabel label_2 = new JLabel("\u6027\u522B");
        label_2.setBounds(72, 100, 52, 18);
        add(label_2);
        
        textField_2 = new JTextField();
        textField_2.setEnabled(false);
        textField_2.setBounds(112, 100, 150, 24);
        add(textField_2);
        textField_2.setColumns(10);
        
        JLabel label_3 = new JLabel("\u5B66\u9662");
        label_3.setBounds(72, 140, 41, 18);
        add(label_3);
        
        textField_3 = new JTextField();
        textField_3.setEnabled(false);
        textField_3.setBounds(112, 140, 150, 24);
        add(textField_3);
        textField_3.setColumns(10);
        
        JLabel label_4 = new JLabel("\u4E13\u4E1A");
        label_4.setBounds(72, 180, 45, 18);
        add(label_4);
        
        textField_4 = new JTextField();
        textField_4.setEnabled(false);
        textField_4.setBounds(112, 180, 150, 24);
        add(textField_4);
        textField_4.setColumns(10);
        
        JLabel label_5 = new JLabel("\u73ED\u7EA7");
        label_5.setBounds(72, 220, 45, 18);
        add(label_5);
        
        textField_5 = new JTextField();
        textField_5.setEnabled(false);
        textField_5.setBounds(112, 220, 150, 24);
        add(textField_5);
        textField_5.setColumns(10);
        
        JButton btnNewButton = new JButton("\u67E5\u8BE2");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
                 Connection sin=Test.getconnectin();
                    String sno=textField.getText();
                    ResultSet rs=null;
                    PreparedStatement stmt=null;
                    try {
                        //牛逼查找
                         stmt=sin.prepareStatement("select * from student where sno=?");
                        stmt.setObject(1,sno);
                        rs=stmt.executeQuery();
                        boolean flag=false;
                        while(rs.next()){
                        String msg=rs.getString("sno")+"\n"+rs.getString("name")+"\n"+rs.getString("sex")+"\n"+rs.getString("department")+"\n"+rs.getString("subject")+"\n"+rs.getString("myclass")+"\n";
                        JOptionPane.showMessageDialog(null,msg,"查詢結(jié)果:",JOptionPane.NO_OPTION );
                        textField_1.setText(rs.getString("name"));
                        textField_2.setText(rs.getString("sex"));
                        textField_3.setText(rs.getString("department"));
                        textField_4.setText(rs.getString("subject"));
                        textField_5.setText(rs.getString("myclass"));
                        flag=true;
                        }
                        if(flag==false) {
                            JOptionPane.showMessageDialog(null,"查無(wú)此人","查詢結(jié)果",JOptionPane.NO_OPTION );
                        }
                        
                            stmt.close();//關(guān)閉數(shù)據(jù)庫(kù)
                            sin.close();
                        } catch (SQLException h) {
                            // TODO Auto-generated catch block
                            h.printStackTrace();
                        }
                    }
                
                    
            
               
             
           

            
        });
        btnNewButton.setBounds(366, 17, 77, 27);
        add(btnNewButton);

    }

}

刪除面板

package 學(xué)籍管理系統(tǒng)視窗;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;


import 數(shù)據(jù)庫(kù).Test;


public class 刪除面板 extends JPanel {
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JTextField textField_4;
    private JTextField textField_5;


    /**
     * Create the panel.
     */
    public 刪除面板() {
setLayout(null);
        
        JLabel label = new JLabel("\u8F93\u5165\u8981\u5220\u9664\u4FE1\u606F\u7684\u5B66\u53F7\uFF1A");
        label.setBounds(37, 22, 189, 18);
        add(label);
        
        textField = new JTextField();
        textField.setBounds(201, 19, 154, 24);
        add(textField);
        textField.setColumns(10);
        
        JLabel label_1 = new JLabel("\u59D3\u540D");
        label_1.setBounds(72, 60, 40, 18);
        add(label_1);
        
        textField_1 = new JTextField();
        textField_1.setEnabled(false);
        textField_1.setBounds(112, 60, 150, 24);
        add(textField_1);
        textField_1.setColumns(10);
        
        JLabel label_2 = new JLabel("\u6027\u522B");
        label_2.setBounds(72, 100, 52, 18);
        add(label_2);
        
        textField_2 = new JTextField();
        textField_2.setEnabled(false);
        textField_2.setBounds(112, 100, 150, 24);
        add(textField_2);
        textField_2.setColumns(10);
        
        JLabel label_3 = new JLabel("\u5B66\u9662");
        label_3.setBounds(72, 140, 41, 18);
        add(label_3);
        
        textField_3 = new JTextField();
        textField_3.setEnabled(false);
        textField_3.setBounds(112, 140, 150, 24);
        add(textField_3);
        textField_3.setColumns(10);
        
        JLabel label_4 = new JLabel("\u4E13\u4E1A");
        label_4.setBounds(72, 180, 45, 18);
        add(label_4);
        
        textField_4 = new JTextField();
        textField_4.setEnabled(false);
        textField_4.setBounds(112, 180, 150, 24);
        add(textField_4);
        textField_4.setColumns(10);
        
        JLabel label_5 = new JLabel("\u73ED\u7EA7");
        label_5.setBounds(72, 220, 45, 18);
        add(label_5);
        
        textField_5 = new JTextField();
        textField_5.setEnabled(false);
        textField_5.setBounds(112, 220, 150, 24);
        add(textField_5);
        textField_5.setColumns(10);
        
        JButton btnNewButton = new JButton("\u67E5\u8BE2");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
                 Connection sin=Test.getconnectin();
                    String sno=textField.getText();
                    ResultSet rs=null;
                    PreparedStatement stmt=null;
                    try {
                        //牛逼查找
                         stmt=sin.prepareStatement("select * from student where sno=?");
                        stmt.setObject(1,sno);
                        rs=stmt.executeQuery();
                        boolean flag=false;
                        while(rs.next()){
                            JOptionPane.showMessageDialog(null,"查詢成功","提示",JOptionPane.NO_OPTION );
                        textField_1.setText(rs.getString("name"));
                        textField_2.setText(rs.getString("sex"));
                        textField_3.setText(rs.getString("department"));
                        textField_4.setText(rs.getString("subject"));
                        textField_5.setText(rs.getString("myclass"));
                        flag=true;
                        }
                        if(flag==false) {
                            JOptionPane.showMessageDialog(null,"查無(wú)此人","查詢結(jié)果",JOptionPane.NO_OPTION );
                        }
                            stmt.close();//關(guān)閉數(shù)據(jù)庫(kù)
                            sin.close();
                        } catch (SQLException h) {
                            // TODO Auto-generated catch block
                            h.printStackTrace();
                        }
                    }
                
                    
            
                
                
                
            
        });
        btnNewButton.setBounds(366, 17, 77, 27);
        add(btnNewButton);
        
        JButton button = new JButton("\u5220\u9664");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
                //刪除操作
                String sno=textField.getText();
                boolean flag;
                Connection sin=Test.getconnectin();
                flag=Test.chongfu(sin,sno);
                System.out.println(flag);
                if(flag) {
                
                Test.delete(sin, sno);
                JOptionPane.showMessageDialog(null,"信息刪除成功!","信息",JOptionPane.INFORMATION_MESSAGE );
                textField.setText("");
                textField_1.setText("");
                textField_2.setText("");
                textField_3.setText("");
                textField_4.setText("");
                textField_5.setText("");
            }
                else
                    JOptionPane.showMessageDialog(null,"該學(xué)號(hào)信息不存在!","信息",JOptionPane.INFORMATION_MESSAGE );
            }
        });
        button.setBounds(72, 257, 113, 27);
        add(button);
        
        JButton button_1 = new JButton("\u91CD\u7F6E");
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
                textField.setText("");
                textField_1.setText("");
                textField_2.setText("");
                textField_3.setText("");
                textField_4.setText("");
                textField_5.setText("");
                JOptionPane.showMessageDialog(null,"重置成功","提示",JOptionPane.NO_OPTION );
                
            }
        });
        button_1.setBounds(217, 257, 113, 27);
        add(button_1);


    }

}

數(shù)據(jù)庫(kù)類

package 數(shù)據(jù)庫(kù);

import java.sql.*;

import javax.swing.JOptionPane;
public class Test {
public final static Connection getconnectin(){
     
    Connection con=null;
    //String driver = "com.mysql.jdbc.Driver"; 8.0不需要加載驅(qū)動(dòng)
    String url = "jdbc:mysql://localhost:3306/gip?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=Asia/Shanghai";
    String user = "root";
    String password = "123456";
    try{
        //Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    //  Class.forName(driver);
        con=DriverManager.getConnection(url,user,password);
        con.setCatalog("gip");
        
    }
    catch(SQLException sqle){
           System.out.println(sqle+"lianjiecuowu");
                }
            catch(Exception e){
                System.out.println(e+"diergecuowu");
            
            }
    return con;
}
//添加數(shù)據(jù)
public final static void insert(Connection con,Object obj[]){
    PreparedStatement stmt=null;
    
    try {
        
        
    stmt=con.prepareStatement("insert into student(sno,name,sex,department,subject,myclass) values(?,?,?,?,?,?)");
        
        stmt.setString(1,obj[0].toString());
        stmt.setString(2,obj[1].toString());
        stmt.setString(3,obj[2].toString());
        stmt.setString(4,obj[3].toString());
        stmt.setString(5,obj[4].toString());
        stmt.setString(6,obj[5].toString());
        stmt.execute();
        
        
        
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null,"shibai","操作提示",JOptionPane.NO_OPTION );
    }
}
//查詢數(shù)據(jù)
public final static ResultSet query(Connection con){
    
    ResultSet rs=null;
    PreparedStatement stmt=null;
    try {
        stmt=con.prepareStatement("select * from student");
         rs=stmt.executeQuery();
        //stmt.close();
        //con.close();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return rs;
}
//判斷學(xué)號(hào)重復(fù)
public final static boolean chongfu(Connection con,String a){
    
    ResultSet rs=null;
    PreparedStatement stmt=null;
    boolean flag=true;;
    try {
        stmt=con.prepareStatement("select sno from student");
         rs=stmt.executeQuery();
         while(rs.next())
         {
             if(a.equalsIgnoreCase(rs.getString("sno")))
            
                 return true;
            
             //System.out.println(rs.getString("sno"));
         }
        //stmt.close();
        //con.close();
         
         
         
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return false;
}

//刪除數(shù)據(jù)
public final static void delete(Connection con,String s){
    try {
        PreparedStatement stmt;
         stmt=con.prepareStatement("delete from student where sno=?");
        stmt.setObject(1,s);
        stmt.execute();
        
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    finally{
        
    }
}

//更新修改數(shù)據(jù)
public final static void update(Connection con,Object obj[]){
    PreparedStatement stmt=null;
    try {
        stmt=con.prepareStatement("update student set name=?,sex=?,department=?,subject=?,myclass=? where sno=?");
        
        stmt.setString(6,obj[0].toString());
        stmt.setString(1,obj[1].toString());
        stmt.setString(2,obj[2].toString());
        stmt.setString(3,obj[3].toString());
        stmt.setString(4,obj[4].toString());
        stmt.setString(5,obj[5].toString());
        stmt.execute();
        
        
        
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null,"shibai","操作提示",JOptionPane.NO_OPTION );
    }
}


}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市鲫懒,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖厚者,帶你破解...
    沈念sama閱讀 207,113評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異迫吐,居然都是意外死亡库菲,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,644評(píng)論 2 381
  • 文/潘曉璐 我一進(jìn)店門志膀,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)蝙昙,“玉大人,你說(shuō)我怎么就攤上這事梧却∑娴撸” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 153,340評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵放航,是天一觀的道長(zhǎng)烈拒。 經(jīng)常有香客問(wèn)我,道長(zhǎng)广鳍,這世上最難降的妖魔是什么荆几? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,449評(píng)論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮赊时,結(jié)果婚禮上吨铸,老公的妹妹穿的比我還像新娘。我一直安慰自己祖秒,他們只是感情好诞吱,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,445評(píng)論 5 374
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著竭缝,像睡著了一般房维。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上抬纸,一...
    開(kāi)封第一講書(shū)人閱讀 49,166評(píng)論 1 284
  • 那天咙俩,我揣著相機(jī)與錄音,去河邊找鬼湿故。 笑死阿趁,一個(gè)胖子當(dāng)著我的面吹牛膜蛔,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播脖阵,決...
    沈念sama閱讀 38,442評(píng)論 3 401
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼飞几,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了独撇?” 一聲冷哼從身側(cè)響起屑墨,我...
    開(kāi)封第一講書(shū)人閱讀 37,105評(píng)論 0 261
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎纷铣,沒(méi)想到半個(gè)月后卵史,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,601評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡搜立,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,066評(píng)論 2 325
  • 正文 我和宋清朗相戀三年以躯,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片啄踊。...
    茶點(diǎn)故事閱讀 38,161評(píng)論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡忧设,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出颠通,到底是詐尸還是另有隱情址晕,我是刑警寧澤,帶...
    沈念sama閱讀 33,792評(píng)論 4 323
  • 正文 年R本政府宣布顿锰,位于F島的核電站谨垃,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏硼控。R本人自食惡果不足惜刘陶,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,351評(píng)論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望牢撼。 院中可真熱鬧匙隔,春花似錦、人聲如沸熏版。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,352評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)纳决。三九已至碰逸,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間阔加,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,584評(píng)論 1 261
  • 我被黑心中介騙來(lái)泰國(guó)打工满钟, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留胜榔,地道東北人胳喷。 一個(gè)月前我還...
    沈念sama閱讀 45,618評(píng)論 2 355
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像夭织,于是被迫代替她去往敵國(guó)和親吭露。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,916評(píng)論 2 344

推薦閱讀更多精彩內(nèi)容

  • 這篇文章是為了介紹自己自學(xué)用過(guò)的Java視頻資料尊惰。全部來(lái)自傳智播客旗下的黑馬程序員讲竿。也感謝傳智播客放出這么多優(yōu)質(zhì)的...
    bravo1988閱讀 2,981評(píng)論 1 5
  • 本文首發(fā)于微信公眾號(hào)「劉望舒」 相關(guān)系列文章 ...
    劉望舒閱讀 3,239評(píng)論 0 8
  • 這個(gè)月就要離開(kāi)北京了。 感慨萬(wàn)千弄屡,貌似自從18歲以后的每一個(gè)日日夜夜题禀,人生總是在不斷遷徙和漂泊中度過(guò)的。從南方三四...
    Badheater閱讀 206評(píng)論 0 0
  • 生活時(shí)時(shí)刻刻讓我們不知所措膀捷。我很迷茫迈嘹,我真的不知道我要停在何處。 尤其假期全庸,我該去往何方秀仲。心理糾結(jié)的不行。唉壶笼,我的...
    莫111閱讀 78評(píng)論 0 0
  • 基礎(chǔ)命令 一:文件 1.創(chuàng)建文件 2.刪除文件 rm + 文件名 有提示的刪除 rm -rf 文件名 無(wú)提示的刪...
    Nolie_6f62閱讀 124評(píng)論 0 1