java实现学生信息管理系统

1 系统需求分析 

学校每年都有新生入学、老生毕业,还有其他各种人事变动。如何有效地管理这些学生的信息,帮助学校和老师掌握学生的情况,这就是学生信息管理系统需要完成的功能。 

1.1 系统功能分析 

本系统主要的功能是收集学生的个人信息,以便向教师提供每个学生在校的情况。系统的主要功能有:

l  ①学生个人信息输入,包括:姓名、性别、院系、生日、籍贯、生源所在地等。

l  ②学生流动情况的输入,包括:转系、休学、复学、退学、毕业。

③奖惩情况的输入。

l  ④学生个人情况查询和修改,包括流动情况和奖罚情况。 

1.2 系统功能模块设计(划分) 

根据系统功能要求可以将系统分解成几个模块来分别设计应用程序界面,如图所示。 

1.3 与其它系统的关系

学生信息管理系统是校园信息管理系统的一个组成部分。它为其它系统,如班级信息管理系统、教学管理系统、成绩单系统、宿舍分配系统等,提供学生的基本情况。同时需要其他系统提供的班级设置和院系设置等情况。这些系统可以使用同一个数据库,直接相互调用所需的数据。 

1.4 数据流程图

学生信息管理系统的数据流程如图所示。

 学生信息管理系统数据流程图 

2 数据库设计

2.1 数据库需求分析 

根据上一节的数据流程图,可以列出以下记录学生信息所需的数据项和数据结构:

l ①学生:学号、姓名、性别、生日、籍贯、所在院系、所在班级。

l ②处罚记录:记录号、级别、处罚对象、记录时间、详细描述、是否生效。

l ③奖励记录:记录号、级别、奖励对象、记录时间、详细描述。

l ④学籍变更记录:记录号、变更情况、记录对象、记录时间、详细描述。

所需的外部数据支持:

l ①班级:班级编号、班级名称、所属院系。

l ②院系:代码、名称。

2.2 数据库概念结构设计 

本系统所需数据的 E-R 模型图。

 

2.3 数据库逻辑结构设计

根据系统 E-R 图,需要设计 4 个数据表来存放学生的信息。为了系统的完整,系统中包括了应用程序设计中所需的 2 个外部数据表。为了优化数据表结构,部分字段采用代码形式,因此需要附加 3 个代码表。这 9 个数据表的结构如表 1 到表 9 所示。

表 1 STUDENT 学生个人信息表   

 

表 2 CHANGE 学籍变更信息表

 

表 3 REWARD 奖励记录信息表

 

表 4 PUNISHMENT 处罚记录信息表

 

表 5 DEPARTMENT 院系信息表

表 6 CLASS 班级信息表

 

表7 密码表

 

表 8 REWARD_LEVELS 奖励等级代码表

 

表 9 PUNISH_LEVELS 处罚等级代码表

 

2.4 数据库的建立 

 

2.4.1 数据库的建立(请设计者完成

不说了,直接上图上代码

 

代码如下

package com.itheima.jdbc;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.HeadlessException;
import javax.swing.JPasswordField;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JRadioButton;
import java.awt.Color;

/**
 * 
 * @author 罗志刚
 * @date 2019年12月21日 下午6:50:00
 * @Description
 */
@SuppressWarnings("serial")
public class Register extends JFrame {
	public int flag = 1;
	JDBCutil query = new JDBCutil();// 创建数据库的操作类对象,用于数据库的各种操作
	private JPanel contentPane;
	private JPasswordField passwordField_1;
	private JTextField textField;

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

	/**
	 * Create the frame.
	 */
	public Register() {
		setTitle("用户登录");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 435, 550);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		setLocationRelativeTo(null);// 窗体居中显示

		JLabel lblNewLabel = new JLabel("账 号:");
		lblNewLabel.setForeground(Color.BLACK);
		lblNewLabel.setHorizontalAlignment(SwingConstants.TRAILING);
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
		lblNewLabel.setBounds(38, 329, 50, 35);
		contentPane.add(lblNewLabel);

		textField = new JTextField();
		textField.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		textField.setBounds(98, 329, 311, 35);
		contentPane.add(textField);
		textField.setColumns(10);

		JLabel label = new JLabel("密 码:");
		label.setHorizontalAlignment(SwingConstants.TRAILING);
		label.setFont(new Font("微软雅黑", Font.BOLD, 16));
		label.setBounds(38, 374, 50, 35);
		contentPane.add(label);

		passwordField_1 = new JPasswordField();
		passwordField_1.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		passwordField_1.setBounds(98, 374, 311, 35);
		contentPane.add(passwordField_1);

		JButton button = new JButton("取消");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				JOptionPane.showMessageDialog(null, "恭喜你已安全退出!", "信息", JOptionPane.INFORMATION_MESSAGE);
				System.exit(0);
			}
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button.setBounds(279, 460, 93, 41);
		contentPane.add(button);

		ButtonGroup group = new ButtonGroup();
		JLabel lblNewLabel_1 = new JLabel("");
		lblNewLabel_1
				.setIcon(new ImageIcon(Register.class.getResource("/ico/u=1173560350,67453878&fm=26&gp=0[1].jpg")));
		lblNewLabel_1.setBounds(0, 0, 424, 283);
		contentPane.add(lblNewLabel_1);

		JRadioButton rdbtnNewRadioButton = new JRadioButton("\u5B66\u751F");
		rdbtnNewRadioButton.setSelected(true); // 默认选择
		rdbtnNewRadioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag = 1;// 学生
			}
		});
		rdbtnNewRadioButton.setFont(new Font("微软雅黑", Font.BOLD, 16));
		rdbtnNewRadioButton.setBounds(128, 416, 69, 23);
		contentPane.add(rdbtnNewRadioButton);

		JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("\u6559\u5E08");
		rdbtnNewRadioButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag = 2;// 教师
			}
		});
		rdbtnNewRadioButton_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
		rdbtnNewRadioButton_1.setBounds(248, 416, 61, 23);
		contentPane.add(rdbtnNewRadioButton_1);
		group.add(rdbtnNewRadioButton_1);
		group.add(rdbtnNewRadioButton);

		JButton btnNewButton = new JButton("登录");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (flag == 1) {
					String sql = "select *from student_password where 账号='" + textField.getText() + "'and 密码='"
							+ new String(passwordField_1.getPassword()) + "'";
					try {
						ResultSet rs = query.query(sql);// 调用数据库的查询方法
						if (textField.getText().length() <= 0 && passwordField_1.getPassword().length <= 0) {
							JOptionPane.showMessageDialog(null, "账号和密码不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						} else if (textField.getText().length() <= 0) {
							JOptionPane.showMessageDialog(null, "账号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						} else if (passwordField_1.getPassword().length <= 0) {
							JOptionPane.showMessageDialog(null, "密码不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						} else if (rs.next()) {
							// 第一个参数是控制弹出对话框相对的中心位置,如果是null,则是在屏幕中间,如果是其它组件参数,则会在其它组件的中心弹出。
							JOptionPane.showMessageDialog(null, "恭喜你已成功登录!", "信息", JOptionPane.INFORMATION_MESSAGE);
							StudentViews frame = new StudentViews();
							frame.setVisible(true);
							dispose();
						} else {
							JOptionPane.showMessageDialog(null, "用户名或者密码不正确!", "警告", JOptionPane.ERROR_MESSAGE);
							textField.requestFocus();
							textField.setText(null);
							passwordField_1.setText(null);
						}
					} catch (HeadlessException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}

				if (flag == 2) {
					String sql = "select *from teacher_password where 账号='" + textField.getText() + "'and 密码='"
							+ new String(passwordField_1.getPassword()) + "'";
					try {
						ResultSet rs = query.query(sql);// 调用数据库的查询方法
						if (textField.getText().length() <= 0 && passwordField_1.getPassword().length <= 0) {
							JOptionPane.showMessageDialog(null, "账号和密码不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						} else if (textField.getText().length() <= 0) {
							JOptionPane.showMessageDialog(null, "账号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						} else if (passwordField_1.getPassword().length <= 0) {
							JOptionPane.showMessageDialog(null, "密码不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						} else if (rs.next()) {
							// 第一个参数是控制弹出对话框相对的中心位置,如果是null,则是在屏幕中间,如果是其它组件参数,则会在其它组件的中心弹出。
							JOptionPane.showMessageDialog(null, "恭喜你已成功登录!", "信息", JOptionPane.INFORMATION_MESSAGE);
							TeacherViews frame = new TeacherViews();
							frame.setVisible(true);
							dispose();
						} else {
							JOptionPane.showMessageDialog(null, "用户名或者密码不正确!", "警告", JOptionPane.ERROR_MESSAGE);
							textField.requestFocus();
							textField.setText(null);
							passwordField_1.setText(null);
						}
					} catch (HeadlessException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
			}
		});
		btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 18));
		btnNewButton.setBounds(156, 460, 93, 41);
		contentPane.add(btnNewButton);

		JButton button_1 = new JButton("注册");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Post frame = new Post();
				frame.setVisible(true);
			}
		});
		button_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button_1.setBounds(37, 460, 93, 41);
		contentPane.add(button_1);
		
		JLabel lblNewLabel_2 = new JLabel("");
		lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_2.setIcon(new ImageIcon(Register.class.getResource("/ico/用户名.png")));
		lblNewLabel_2.setBounds(27, 329, 26, 35);
		contentPane.add(lblNewLabel_2);
		
		JLabel label_1 = new JLabel("");
		label_1.setIcon(new ImageIcon(Register.class.getResource("/ico/密码.png")));
		label_1.setFont(new Font("宋体", Font.PLAIN, 14));
		label_1.setBounds(27, 374, 26, 35);
		contentPane.add(label_1);

	}
}
package com.itheima.jdbc;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

/**
* @author 罗志刚
* @date 2019年12月27日 上午9:37:52
* @Description   
*/
@SuppressWarnings("serial")
public class Delete extends JFrame {
	public int flag=1;
	private JPanel contentPane;
	private JTextField textField;

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

	/**
	 * Create the frame.
	 */
	public Delete() {
		setFont(new Font("微软雅黑", Font.PLAIN, 14));
		setTitle("删除界面");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 607, 391);
		contentPane = new JPanel();
		contentPane.setBackground(Color.CYAN);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		setLocationRelativeTo(null);//将窗口居中
		
		JLabel lblNewLabel = new JLabel("请选择要删除的方式");
		lblNewLabel.setForeground(Color.BLUE);
		lblNewLabel.setBackground(Color.WHITE);
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 23));
		lblNewLabel.setBounds(189, 23, 216, 31);
		contentPane.add(lblNewLabel);
		
		JRadioButton rdbtnNewRadioButton = new JRadioButton("按学号删除");
		rdbtnNewRadioButton.setBackground(Color.CYAN);
		rdbtnNewRadioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag=1;
			}
		});
		rdbtnNewRadioButton.setSelected(true);
		rdbtnNewRadioButton.setFont(new Font("微软雅黑", Font.BOLD, 18));
		rdbtnNewRadioButton.setBounds(92, 82, 121, 23);
		contentPane.add(rdbtnNewRadioButton);
		
		JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("按班级删除");
		rdbtnNewRadioButton_1.setBackground(Color.CYAN);
		rdbtnNewRadioButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag=2;
			}
		});
		rdbtnNewRadioButton_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		rdbtnNewRadioButton_1.setBounds(92, 126, 121, 23);
		contentPane.add(rdbtnNewRadioButton_1);
		
		JRadioButton rdbtnNewRadioButton_2 = new JRadioButton("按姓名删除");
		rdbtnNewRadioButton_2.setBackground(Color.CYAN);
		rdbtnNewRadioButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag=3;
			}
		});
		rdbtnNewRadioButton_2.setFont(new Font("微软雅黑", Font.BOLD, 18));
		rdbtnNewRadioButton_2.setBounds(92, 170, 121, 23);
		contentPane.add(rdbtnNewRadioButton_2);
		
		JRadioButton rdbtnNewRadioButton_3 = new JRadioButton("按专业删除");
		rdbtnNewRadioButton_3.setBackground(Color.CYAN);
		rdbtnNewRadioButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag=4;
			}
		});
		rdbtnNewRadioButton_3.setFont(new Font("微软雅黑", Font.BOLD, 18));
		rdbtnNewRadioButton_3.setBounds(92, 216, 121, 23);
		contentPane.add(rdbtnNewRadioButton_3);
		
		JButton btnNewButton = new JButton("确认");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
					if(flag==1) {
						if(textField.getText() == null || textField.getText().isEmpty()) {
							JOptionPane.showMessageDialog(null, "输入的学号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						}else {
							String s1=textField.getText();
							JDBCutil jdbc=new JDBCutil();
							String sql="delete from student where 学号=?";//先把改学号删除,再重新录入
							jdbc.testUpdate(sql, s1);
							JOptionPane.showMessageDialog(null, "恭喜你删除成功!", "信息", JOptionPane.INFORMATION_MESSAGE);
						}											
					}else if(flag==2) {
						if(textField.getText() == null || textField.getText().isEmpty()) {
							JOptionPane.showMessageDialog(null, "输入的班级不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						}else {
							String s1=textField.getText();
							JDBCutil jdbc=new JDBCutil();
							String sql="delete from student where 班级=?";//先把改学号删除,再重新录入
							jdbc.testUpdate(sql, s1);
							JOptionPane.showMessageDialog(null, "恭喜你删除成功!", "信息", JOptionPane.INFORMATION_MESSAGE);
							}											
					}else if(flag==3) {
						if(textField.getText() == null || textField.getText().isEmpty()) {
							JOptionPane.showMessageDialog(null, "输入的姓名不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						}else {
							String s1=textField.getText();
							JDBCutil jdbc=new JDBCutil();
							String sql="delete from student where 姓名=?";//先把改学号删除,再重新录入
							jdbc.testUpdate(sql, s1);	
							JOptionPane.showMessageDialog(null, "恭喜你删除成功!", "信息", JOptionPane.INFORMATION_MESSAGE);
							}											
					}else if(flag==4) {
						if(textField.getText() == null || textField.getText().isEmpty()) {
							JOptionPane.showMessageDialog(null, "输入的专业不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						}else {
							String s1=textField.getText();
							JDBCutil jdbc=new JDBCutil();
							String sql="delete from student where 专业=?";//先把改学号删除,再重新录入
							jdbc.testUpdate(sql, s1);	
							JOptionPane.showMessageDialog(null, "恭喜你删除成功!", "信息", JOptionPane.INFORMATION_MESSAGE);
                             }											
					}			
			}
		});
		btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 18));
		btnNewButton.setBounds(163, 279, 93, 42);
		contentPane.add(btnNewButton);
		
		ButtonGroup group =  new ButtonGroup();
		group.add(rdbtnNewRadioButton);
		group.add(rdbtnNewRadioButton_1);
		group.add(rdbtnNewRadioButton_2);
		group.add(rdbtnNewRadioButton_3);
		
		textField = new JTextField();
		textField.setFont(new Font("微软雅黑", Font.BOLD, 15));
		textField.setBounds(258, 148, 239, 31);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JButton button = new JButton("退出");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "恭喜你已安全退出!", "信息", JOptionPane.INFORMATION_MESSAGE);
				dispose();
			}
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button.setBounds(370, 279, 93, 42);
		contentPane.add(button);
	}

}
package com.itheima.jdbc;


import java.awt.EventQueue;
import java.awt.Font;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import java.awt.Color;

/**
* @author 罗志刚
* @date 2019年12月23日 下午9:18:18
* @Description   
*/
@SuppressWarnings("serial")
public class InformationInput extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;

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

	/**
	 * Create the frame.
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public InformationInput() {		
		setFont(new Font("微软雅黑", Font.PLAIN, 14));
		setTitle("个人信息的录入");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 556);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		setLocationRelativeTo(null);//将窗口居中
		
		JLabel lblNewLabel = new JLabel("学 号:");
		lblNewLabel.setForeground(Color.WHITE);
		lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		lblNewLabel.setBounds(10, 10, 42, 15);
		contentPane.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField.setBounds(62, 4, 271, 30);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel label = new JLabel("姓 名:");
		label.setForeground(Color.WHITE);
		label.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label.setBounds(10, 55, 47, 15);
		contentPane.add(label);
		
		textField_1 = new JTextField();
		textField_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField_1.setColumns(10);
		textField_1.setBounds(62, 49, 271, 30);
		contentPane.add(textField_1);
		
		JLabel label_1 = new JLabel("性 别:");
		label_1.setForeground(Color.WHITE);
		label_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_1.setBounds(10, 100, 47, 15);
		contentPane.add(label_1);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "男", "女"}));
		comboBox.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		comboBox.setToolTipText("");
		comboBox.setBounds(62, 98, 89, 21);
		contentPane.add(comboBox);
		
		JLabel label_2 = new JLabel("生 日:");
		label_2.setForeground(Color.WHITE);
		label_2.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		label_2.setBounds(10, 139, 47, 15);
		contentPane.add(label_2);
		
		textField_2 = new JTextField();
		textField_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField_2.setColumns(10);
		textField_2.setBounds(62, 133, 271, 30);
		contentPane.add(textField_2);
		
		JLabel label_3 = new JLabel("年 龄:");
		label_3.setForeground(Color.WHITE);
		label_3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_3.setBounds(10, 183, 47, 15);
		contentPane.add(label_3);
		
		textField_3 = new JTextField();
		textField_3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField_3.setColumns(10);
		textField_3.setBounds(62, 177, 271, 30);
		contentPane.add(textField_3);
		
		JLabel label_4 = new JLabel("籍 贯:");
		label_4.setForeground(Color.WHITE);
		label_4.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_4.setBounds(10, 225, 47, 15);
		contentPane.add(label_4);
		
		JComboBox comboBox_1 = new JComboBox();
		comboBox_1.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "北京市 ", "天津市", "上海市 ", "重庆市", "河北省 ", "河南省 ", "云南省 ", "辽宁省 ", "黑龙江省 ", "湖南省", "安徽省", "山东省 ", "新疆维吾尔", "江苏省", "浙江省", "江西省", "湖北省", "广西壮族", "甘肃省", "山西省", "内蒙古", "陕西省", "吉林省", "福建省", "贵州省", "广东省", "青海省", "西藏", "四川省", "宁夏回族", "海南省"}));
		comboBox_1.setBounds(62, 225, 89, 21);
		contentPane.add(comboBox_1);
		
		JLabel label_5 = new JLabel("院 系:");
		label_5.setForeground(Color.WHITE);
		label_5.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_5.setBounds(10, 264, 47, 15);
		contentPane.add(label_5);
		
		JComboBox comboBox_2 = new JComboBox();
		comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "潇湘学院", "计算机学院", "软件学院", "教育学院", "体育科学学院", "医学院", "商学院,", "艺术学院", "政治学院", "管理学院,", "外国语学院,", "生命科学学院", "机械工程学院", "电子信息学院", "电气工程学院", "化学化工学院", "地理科学学院"}));
		comboBox_2.setToolTipText("");
		comboBox_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		comboBox_2.setBounds(62, 262, 89, 21);
		contentPane.add(comboBox_2);
		
		JComboBox comboBox_3 = new JComboBox();
		comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "软件工程", "经济学", "统计学", "哲学", "材料成型及控制工程、", "市场营销", "会计学", "生物工程", "人力资源管", "机械设计制造及自动化、", "通信工程", "自动化", "计算机科学与技术", "信息工程", "电子信息工程", "测绘工程", "英语", "翻译", "化学工程与工艺、", "制药工程"}));
		comboBox_3.setToolTipText("");
		comboBox_3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		comboBox_3.setBounds(62, 297, 89, 21);
		contentPane.add(comboBox_3);
		
		JLabel label_6 = new JLabel("专 业:");
		label_6.setForeground(Color.WHITE);
		label_6.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_6.setBounds(10, 301, 47, 15);
		contentPane.add(label_6);
		
		JLabel label_7 = new JLabel("班 级:");
		label_7.setForeground(Color.WHITE);
		label_7.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_7.setBounds(10, 341, 47, 15);
		contentPane.add(label_7);
		
		textField_4 = new JTextField();
		textField_4.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField_4.setColumns(10);
		textField_4.setBounds(62, 335, 271, 30);
		contentPane.add(textField_4);
		
		JLabel lblPhone = new JLabel("电 话:");
		lblPhone.setForeground(Color.WHITE);
		lblPhone.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		lblPhone.setBounds(10, 390, 90, 15);
		contentPane.add(lblPhone);
		
		textField_5 = new JTextField();
		textField_5.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField_5.setColumns(10);
		textField_5.setBounds(62, 384, 271, 30);
		contentPane.add(textField_5);
		
		JButton button = new JButton("确定");
		button.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button.setBounds(22, 446, 93, 41);
		contentPane.add(button);
		button.addActionListener(new ActionListener() { //数据的插入
			public void actionPerformed(ActionEvent e) {
				String s1=textField.getText();
				String s2=textField_1.getText();
				String s3=(String)comboBox.getSelectedItem();
				String s4=textField_2.getText();
				String s5=textField_3.getText();
				String s6=(String)comboBox_1.getSelectedItem();
				String s7=(String)comboBox_2.getSelectedItem();
				String s8=(String)comboBox_3.getSelectedItem();
				String s9=textField_4.getText();
				String s10=textField_5.getText();
				if(s1 == null || s1.isEmpty()){
					JOptionPane.showMessageDialog(null, "学号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s2 == null || s2.isEmpty()) {
					JOptionPane.showMessageDialog(null, "姓名不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s3 == null || s3.isEmpty()) {
					JOptionPane.showMessageDialog(null, "性别不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s4 == null || s4.isEmpty()) {
					JOptionPane.showMessageDialog(null, "生日不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s5 == null || s5.isEmpty()) {
					JOptionPane.showMessageDialog(null, "年龄不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s6 == null || s6.isEmpty()) {
					JOptionPane.showMessageDialog(null, "籍贯不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s7 == null || s7.isEmpty()) {
					JOptionPane.showMessageDialog(null, "院系不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s8 == null || s8.isEmpty()) {
					JOptionPane.showMessageDialog(null, "专业不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s9 == null || s9.isEmpty()) {
					JOptionPane.showMessageDialog(null, "班级不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s10 == null || s10.isEmpty()) {
					JOptionPane.showMessageDialog(null, "电话不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else {
					String sql="insert into student(学号,姓名,性别,生日,年龄,籍贯 ,院系,专业,班级,电话) values(?,?,?,?,?,?,?,?,?,?)";
					JDBCutil jdbc=new JDBCutil();
					jdbc.testUpdate(sql, s1,s2,s3,s4,s5,s6,s7,s8,s9,s10);
					JOptionPane.showMessageDialog(null, "信息录入成功!", "信息", JOptionPane.INFORMATION_MESSAGE);
				}
			}
		});
		
		JButton button_1 = new JButton("取消");
		button_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button_1.setBounds(300, 446, 93, 41);
		contentPane.add(button_1);
		
		JButton button_2 = new JButton("再次录入");
		button_2.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.INFORMATION_MESSAGE);
			}
		});
		button_2.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button_2.setBounds(158, 446, 111, 41);
		contentPane.add(button_2);
		
		JLabel lblNewLabel_1 = new JLabel("");
		lblNewLabel_1.setIcon(new ImageIcon(InformationInput.class.getResource("/ico/653AD1ADFA0F5A89886F47B2C3C91595.jpg")));
		lblNewLabel_1.setBounds(0, 0, 434, 517);
		contentPane.add(lblNewLabel_1);
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "恭喜你已安全退出!", "信息", JOptionPane.INFORMATION_MESSAGE);
				dispose();
			}
		});

	}
}
package com.itheima.jdbc;


import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import java.awt.Color;

/**
* @author 罗志刚
* @date 2019年12月23日 下午8:31:26
* @Description   
*/
@SuppressWarnings("serial")
public class InformationOutput extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;

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

	/**
	 * Create the frame.
	 * @return 
	 */


	@SuppressWarnings({ "unchecked", "rawtypes" })
	public InformationOutput() {
		setFont(new Font("微软雅黑", Font.PLAIN, 14));
		setTitle("个人信息的修改");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 556);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		setLocationRelativeTo(null);//将窗口居中
		
		JLabel lblNewLabel = new JLabel("学 号:");
		lblNewLabel.setForeground(Color.WHITE);
		lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		lblNewLabel.setBounds(10, 16, 47, 15);
		contentPane.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField.setBounds(62, 10, 271, 30);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel label = new JLabel("姓 名:");
		label.setForeground(Color.WHITE);
		label.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label.setBounds(10, 55, 47, 15);
		contentPane.add(label);
		
		textField_1 = new JTextField();
		textField_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField_1.setColumns(10);
		textField_1.setBounds(62, 49, 271, 30);
		contentPane.add(textField_1);
		
		JLabel label_1 = new JLabel("性 别:");
		label_1.setForeground(Color.WHITE);
		label_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_1.setBounds(10, 100, 47, 15);
		contentPane.add(label_1);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "男", "女"}));
		comboBox.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		comboBox.setToolTipText("");
		comboBox.setBounds(62, 98, 89, 21);
		contentPane.add(comboBox);
		
		JLabel label_2 = new JLabel("生 日:");
		label_2.setForeground(Color.WHITE);
		label_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_2.setBounds(10, 139, 47, 15);
		contentPane.add(label_2);
		
		textField_2 = new JTextField();
		textField_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField_2.setColumns(10);
		textField_2.setBounds(62, 133, 271, 30);
		contentPane.add(textField_2);	
		
		JLabel label_3 = new JLabel("年 龄:");
		label_3.setForeground(Color.WHITE);
		label_3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_3.setBounds(10, 183, 47, 15);
		contentPane.add(label_3);
		
		textField_3 = new JTextField();
		textField_3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField_3.setColumns(10);
		textField_3.setBounds(62, 177, 271, 30);
		contentPane.add(textField_3);
		
		JLabel label_4 = new JLabel("籍 贯:");
		label_4.setForeground(Color.WHITE);
		label_4.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_4.setBounds(10, 225, 47, 15);
		contentPane.add(label_4);
		
		JComboBox comboBox_1 = new JComboBox();
		comboBox_1.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "北京市 ", "天津市", "上海市 ", "重庆市", "河北省 ", "河南省 ", "云南省 ", "辽宁省 ", "黑龙江省 ", "湖南省", "安徽省", "山东省 ", "新疆维吾尔", "江苏省", "浙江省", "江西省", "湖北省", "广西壮族", "甘肃省", "山西省", "内蒙古", "陕西省", "吉林省", "福建省", "贵州省", "广东省", "青海省", "西藏", "四川省", "宁夏回族", "海南省"}));
		comboBox_1.setBounds(62, 225, 89, 21);
		contentPane.add(comboBox_1);
		
		JLabel label_5 = new JLabel("院 系:");
		label_5.setForeground(Color.WHITE);
		label_5.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_5.setBounds(10, 264, 47, 15);
		contentPane.add(label_5);
		
		JComboBox comboBox_2 = new JComboBox();
		comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "潇湘学院", "计算机学院", "软件学院", "教育学院", "体育科学学院", "医学院", "商学院,", "艺术学院", "政治学院", "管理学院,", "外国语学院,", "生命科学学院", "机械工程学院", "电子信息学院", "电气工程学院", "化学化工学院", "地理科学学院"}));
		comboBox_2.setToolTipText("");
		comboBox_2.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		comboBox_2.setBounds(62, 262, 89, 21);
		contentPane.add(comboBox_2);
		
		JComboBox comboBox_3 = new JComboBox();
		comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "软件工程", "经济学", "统计学", "哲学", "材料成型及控制工程、", "市场营销", "会计学", "生物工程", "人力资源管", "机械设计制造及自动化、", "通信工程", "自动化", "计算机科学与技术", "信息工程", "电子信息工程", "测绘工程、", "化学工程与工艺、", "制药工程"}));
		comboBox_3.setToolTipText("");
		comboBox_3.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		comboBox_3.setBounds(62, 297, 89, 21);
		contentPane.add(comboBox_3);
		
		JLabel label_6 = new JLabel("专 业:");
		label_6.setForeground(Color.WHITE);
		label_6.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_6.setBounds(10, 301, 47, 15);
		contentPane.add(label_6);
		
		JLabel label_7 = new JLabel("班 级:");
		label_7.setForeground(Color.WHITE);
		label_7.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label_7.setBounds(10, 341, 47, 15);
		contentPane.add(label_7);
		
		textField_4 = new JTextField();
		textField_4.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField_4.setColumns(10);
		textField_4.setBounds(62, 335, 271, 30);
		contentPane.add(textField_4);
		
		JButton button = new JButton("确定");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String s1=textField.getText();
				String s2=textField_1.getText();
				String s3=(String)comboBox.getSelectedItem();
				String s4=textField_2.getText();
				String s5=textField_3.getText();
				String s6=(String)comboBox_1.getSelectedItem();
				String s7=(String)comboBox_2.getSelectedItem();
				String s8=(String)comboBox_3.getSelectedItem();
				String s9=textField_4.getText();
				String s10=textField_5.getText();
				if(s1 == null || s1.isEmpty()){
					JOptionPane.showMessageDialog(null, "学号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s2 == null || s2.isEmpty()) {
					JOptionPane.showMessageDialog(null, "姓名不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s3 == null || s3.isEmpty()) {
					JOptionPane.showMessageDialog(null, "性别不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s4 == null || s4.isEmpty()) {
					JOptionPane.showMessageDialog(null, "生日不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s5 == null || s5.isEmpty()) {
					JOptionPane.showMessageDialog(null, "年龄不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s6 == null || s6.isEmpty()) {
					JOptionPane.showMessageDialog(null, "籍贯不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s7 == null || s7.isEmpty()) {
					JOptionPane.showMessageDialog(null, "院系不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s8 == null || s8.isEmpty()) {
					JOptionPane.showMessageDialog(null, "专业不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s9 == null || s9.isEmpty()) {
					JOptionPane.showMessageDialog(null, "班级不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else if(s10 == null || s10.isEmpty()) {
					JOptionPane.showMessageDialog(null, "电话不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else {
					String sql="insert into student(学号,姓名,性别,生日,年龄,籍贯 ,院系,专业,班级,电话) values(?,?,?,?,?,?,?,?,?,?)";
					JDBCutil jdbc=new JDBCutil();
					jdbc.testUpdate(sql, s1,s2,s3,s4,s5,s6,s7,s8,s9,s10);
					JOptionPane.showMessageDialog(null, "信息录入成功!", "信息", JOptionPane.INFORMATION_MESSAGE);
				}
			}
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button.setBounds(72, 446, 93, 41);
		contentPane.add(button);
		
		JButton button_1 = new JButton("退出");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		button_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button_1.setBounds(255, 446, 93, 41);
		contentPane.add(button_1);
		
		JLabel lblPhone = new JLabel("电 话:");
		lblPhone.setForeground(Color.WHITE);
		lblPhone.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		lblPhone.setBounds(10, 390, 90, 15);
		contentPane.add(lblPhone);
		
		textField_5 = new JTextField();
		textField_5.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		textField_5.setColumns(10);
		textField_5.setBounds(62, 384, 271, 30);
		contentPane.add(textField_5);
		
		JLabel lblNewLabel_1 = new JLabel("");
		lblNewLabel_1.setIcon(new ImageIcon(InformationOutput.class.getResource("/ico/653AD1ADFA0F5A89886F47B2C3C91595.jpg")));
		lblNewLabel_1.setBounds(0, 4, 434, 503);
		contentPane.add(lblNewLabel_1);
		

	}
}
package com.itheima.jdbc;


import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;

/**
* @author 罗志刚
* @date 2019年12月25日 下午3:48:56
* @Description   
*/
@SuppressWarnings("serial")
public class InformationRepair extends JFrame {

	private JPanel contentPane;
	private JTextField textField;

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

	/**
	 * Create the frame.
	 */
	public InformationRepair() {
		setFont(new Font("微软雅黑", Font.PLAIN, 14));
		setTitle("个人信息修改界面");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 648, 364);
		contentPane = new JPanel();
		contentPane.setBackground(Color.CYAN);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		setLocationRelativeTo(null);// 窗体居中显示
		
		JLabel lblNewLabel = new JLabel("请输入您的学号:");
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
		lblNewLabel.setBounds(59, 76, 144, 34);
		contentPane.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setFont(new Font("微软雅黑", Font.BOLD, 16));
		textField.setBounds(204, 76, 277, 35);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JButton button = new JButton("确认");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String s1=textField.getText();
				if(s1 == null || s1.isEmpty()){
					JOptionPane.showMessageDialog(null, "输入的学号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else {
					JDBCutil jdbc=new JDBCutil();
					String sql="delete from student where 学号=?";//先把改学号删除,再重新录入
					jdbc.testUpdate(sql, s1);
					InformationOutput frame = new InformationOutput();
					frame.setVisible(true);
				}
			}
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button.setBounds(152, 212, 93, 42);
		contentPane.add(button);
		
		JButton button_1 = new JButton("退出");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "恭喜你已安全退出!", "信息", JOptionPane.INFORMATION_MESSAGE);
				dispose();
			}
		});
		button_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button_1.setBounds(400, 212, 93, 42);
		contentPane.add(button_1);
	}

}
package com.itheima.jdbc;

import java.sql.*;
import com.mysql.cj.jdbc.result.ResultSetMetaData;
import com.mysql.cj.protocol.x.ResultMessageListener;
/**
 * 
* @author 罗志刚
* @date 2019年12月21日 下午6:49:22
* @Description
 */
@SuppressWarnings("unused")
public class JDBCutil {
	private Connection conn=null;
	private PreparedStatement prpstmt=null;
	ResultSet rs=null;
	private  void creatConnect() { 
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			String url="jdbc:mysql://127.0.0.1:3306/jdbc?serverTimezone=GMT%2B8";
			String username="root";
			String password="1855010107lzgLZG";
			conn=DriverManager.getConnection(url,username,password);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}
	private void closeConnect() {
		if(conn!=null)
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	private void closeRs() {
		if(rs!=null)
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	private void closePrpstmt() {
		if(rs!=null)
			try {
				prpstmt.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	//通用的增删改操作
	public void testUpdate(String sql,Object ...args) {//sql当中占位符的个数应该与可变形参的长度相同
		//1.获取数据库的连接
		try {
			creatConnect();
			//2.预编译SQL语句,返回PreparedStatement实例
			prpstmt=conn.prepareStatement(sql);
			//3.填充占位符
			for(int i=0;i<args.length;i++) {
				prpstmt.setObject(i+1, args[i]);
			}
			//4.执行
			prpstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			//5.资源的关闭
			closePrpstmt();
			closeConnect();
		}	
	}
	public  ResultSet query(String sql) {
		try {
			creatConnect();
			prpstmt=conn.prepareStatement(sql);
			rs=prpstmt.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		return rs;
	}
}

package com.itheima.jdbc;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.ImageIcon;
import java.awt.Color;

/** 
 * 
* @author 罗志刚
* @date 2019年12月26日 下午6:52:21
* @Description
 */
@SuppressWarnings("serial")
public class Post extends JFrame {
	public int flag=1;
	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;
	private JButton button_1;
	JDBCutil query = new JDBCutil();/// 创建数据库的操作类对象,用于数据库的各种操作

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

	/**
	 * Create the frame.
	 */
	public Post() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 478, 360);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		setLocationRelativeTo(null);//将窗口居中
		
		textField = new JTextField();
		textField.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		textField.setColumns(10);
		textField.setBounds(84, 44, 339, 35);
		contentPane.add(textField);
		
		
		JLabel label = new JLabel("账 号:");
		label.setForeground(Color.WHITE);
		label.setBackground(Color.WHITE);
		label.setHorizontalAlignment(SwingConstants.TRAILING);
		label.setFont(new Font("微软雅黑", Font.BOLD, 16));
		label.setBounds(21, 44, 53, 35);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("密 码:");
		label_1.setForeground(Color.WHITE);
		label_1.setHorizontalAlignment(SwingConstants.TRAILING);
		label_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
		label_1.setBounds(21, 103, 53, 35);
		contentPane.add(label_1);
		
		passwordField = new JPasswordField();
		passwordField.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		passwordField.setBounds(84, 103, 339, 35);
		contentPane.add(passwordField);
		
		
		ButtonGroup group =  new ButtonGroup();
		JRadioButton rdbtnNewRadioButton = new JRadioButton("学生");
		rdbtnNewRadioButton.setBackground(Color.CYAN);
		rdbtnNewRadioButton.setForeground(Color.BLACK);
		rdbtnNewRadioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				 flag=1;//学生		
			}
		});
		rdbtnNewRadioButton.setSelected(true);
		rdbtnNewRadioButton.setFont(new Font("微软雅黑", Font.BOLD, 16));
		rdbtnNewRadioButton.setBounds(111, 182, 73, 23);
		contentPane.add(rdbtnNewRadioButton);
		
		JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("教师");
		rdbtnNewRadioButton_1.setBackground(Color.CYAN);
		rdbtnNewRadioButton_1.setForeground(Color.BLACK);
		rdbtnNewRadioButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				 flag=2;//教师			
			}
		});
		rdbtnNewRadioButton_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
		rdbtnNewRadioButton_1.setBounds(273, 182, 66, 23);
		contentPane.add(rdbtnNewRadioButton_1);
		group.add(rdbtnNewRadioButton_1);
		group.add(rdbtnNewRadioButton);
		
		button_1 = new JButton("确认");
		button_1.setIcon(null);
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String s1=textField.getText();
				String s2=new String(passwordField.getPassword());
				if(flag==1) {
					if(s1 == null || s1.isEmpty()){
					JOptionPane.showMessageDialog(null, "账号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
					}else if(s2 == null || s2.isEmpty()) {
						JOptionPane.showMessageDialog(null, "密码不能为空", "警告", JOptionPane.ERROR_MESSAGE);
					}else  {
						String sql="insert into student_password(账号,密码) values(?,?)";
						JDBCutil jdbc=new JDBCutil();
						jdbc.testUpdate(sql, s1,s2);
						JOptionPane.showMessageDialog(null, "恭喜你注册成功!", "消息", JOptionPane.INFORMATION_MESSAGE);
						dispose();	
					}
				}else if(flag==2) {
					if(s1 == null || s1.isEmpty()){
					JOptionPane.showMessageDialog(null, "账号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
					}else if(s2 == null || s2.isEmpty()) {
						JOptionPane.showMessageDialog(null, "密码不能为空", "警告", JOptionPane.ERROR_MESSAGE);
					}else  {
						String sql="insert into teacher_password(账号,密码) values(?,?)";
						JDBCutil jdbc=new JDBCutil();
						jdbc.testUpdate(sql, s1,s2);
						JOptionPane.showMessageDialog(null, "恭喜你注册成功!", "消息", JOptionPane.INFORMATION_MESSAGE);
						dispose();	
					}
				}	
			}
		});
		button_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button_1.setBounds(188, 227, 93, 41);
		contentPane.add(button_1);
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(Post.class.getResource("/ico/C2BD2E79456D9B8F50203CAEF5FBA185.jpg")));
		lblNewLabel.setBounds(0, 0, 462, 308);
		contentPane.add(lblNewLabel);

	}
}
package com.itheima.jdbc;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

/**
* @author 罗志刚
* @date 2019年12月26日 上午10:37:25
* @Description   
*/
@SuppressWarnings("serial")
public class Student_Punish extends JFrame {

	private JPanel contentPane;
	private JTextField textField;

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

	/**
	 * Create the frame.
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Student_Punish() {
		setFont(new Font("微软雅黑", Font.PLAIN, 14));
		setTitle("奖励情况输入");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 578, 325);
		contentPane = new JPanel();
		contentPane.setBackground(Color.ORANGE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		setLocationRelativeTo(null);//将窗口居中
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("请输入你要改变的学生惩罚的学号:");
		lblNewLabel.setForeground(Color.BLUE);
		lblNewLabel.setBackground(Color.BLUE);
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
		lblNewLabel.setBounds(10, 29, 285, 40);
		contentPane.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		textField.setColumns(10);
		textField.setBounds(292, 34, 260, 33);
		contentPane.add(textField);
		
		
		JLabel lblNewLabel_1 = new JLabel("请输入惩罚变更代码:");
		lblNewLabel_1.setForeground(Color.BLUE);
		lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		lblNewLabel_1.setBounds(52, 102, 171, 40);
		contentPane.add(lblNewLabel_1);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "0", "1", "2", "3", "4", "5", "6"}));
		comboBox.setBounds(224, 108, 84, 33);
		contentPane.add(comboBox);
		
		JButton button = new JButton("确认");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String s1=textField.getText();
				if(s1 == null || s1.isEmpty()){
					JOptionPane.showMessageDialog(null, "输入的学号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else {
					JDBCutil jdbc=new JDBCutil();
					String sql="update student_punish set CODE=? where 学号=?";	
					String s2=(String)comboBox.getSelectedItem();
					String s3=textField.getText();
					jdbc.testUpdate(sql, s2,s3);
					JOptionPane.showMessageDialog(null, "恭喜修改成功!", "信息", JOptionPane.INFORMATION_MESSAGE);
				}				
			}
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button.setBounds(117, 190, 93, 42);
		contentPane.add(button);
		
		JButton button_1 = new JButton("退出");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "你已成功退出!", "信息", JOptionPane.INFORMATION_MESSAGE);
				dispose();
			}
		});
		button_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button_1.setBounds(351, 190, 93, 42);
		contentPane.add(button_1);
		

	
	}

}
package com.itheima.jdbc;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

/**
* @author 罗志刚
* @date 2019年12月26日 上午10:21:24
* @Description   
*/
@SuppressWarnings("serial")
public class Student_Reward extends JFrame {

	private JPanel contentPane;
	private JTextField textField;

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

	/**
	 * Create the frame.
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Student_Reward() {
		setFont(new Font("微软雅黑", Font.PLAIN, 14));
		setTitle("奖励情况输入");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 578, 325);
		contentPane = new JPanel();
		contentPane.setBackground(Color.GREEN);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		setLocationRelativeTo(null);//将窗口居中
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("请输入你要改变的学生奖励的学号:");
		lblNewLabel.setForeground(Color.BLUE);
		lblNewLabel.setBackground(Color.BLUE);
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
		lblNewLabel.setBounds(10, 29, 285, 40);
		contentPane.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		textField.setColumns(10);
		textField.setBounds(292, 36, 260, 33);
		contentPane.add(textField);
		
		JLabel lblNewLabel_1 = new JLabel("请输入奖励变更代码:");
		lblNewLabel_1.setForeground(Color.BLUE);
		lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		lblNewLabel_1.setBounds(52, 102, 171, 40);
		contentPane.add(lblNewLabel_1);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "0", "1", "2", "3", "4", "5", "6"}));
		comboBox.setBounds(224, 108, 84, 33);
		contentPane.add(comboBox);
		
		JButton button = new JButton("确认");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String s1=textField.getText();
				if(s1 == null || s1.isEmpty()){
					JOptionPane.showMessageDialog(null, "输入的学号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else { 
				JDBCutil jdbc=new JDBCutil();
				String sql="update student_reward set CODE=? where 学号=?";	
				String s2=(String)comboBox.getSelectedItem();
				String s3=textField.getText();
				jdbc.testUpdate(sql, s2,s3);
				JOptionPane.showMessageDialog(null, "恭喜修改成功!", "信息", JOptionPane.INFORMATION_MESSAGE);
			}
				}
				
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button.setBounds(117, 190, 93, 42);
		contentPane.add(button);
		
		JButton button_1 = new JButton("退出");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "你已成功退出!", "信息", JOptionPane.INFORMATION_MESSAGE);
				dispose();
			}
		});
		button_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button_1.setBounds(351, 190, 93, 42);
		contentPane.add(button_1);
	}

}
package com.itheima.jdbc;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
* @author 罗志刚
* @date 2019年12月26日 上午9:48:15
* @Description   
*/
@SuppressWarnings("serial")
public class StudentChange extends JFrame {

	private JPanel contentPane;
	private JTextField textField;

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

	/**
	 * Create the frame.
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public StudentChange() {
		setFont(new Font("微软雅黑", Font.PLAIN, 14));
		setTitle("学籍改变输入");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 578, 325);
		contentPane = new JPanel();
		contentPane.setBackground(Color.MAGENTA);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		setLocationRelativeTo(null);//将窗口居中
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("请输入你要改变的学生学籍的学号:");
		lblNewLabel.setForeground(Color.BLUE);
		lblNewLabel.setBackground(Color.BLUE);
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
		lblNewLabel.setBounds(10, 29, 285, 40);
		contentPane.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		textField.setBounds(292, 35, 260, 33);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("请输入学籍变更代码:");
		lblNewLabel_1.setForeground(Color.BLUE);
		lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		lblNewLabel_1.setBounds(52, 102, 171, 40);
		contentPane.add(lblNewLabel_1);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "0", "1", "2", "3", "4"}));
		comboBox.setBounds(224, 108, 84, 33);
		contentPane.add(comboBox);
		
		JButton button = new JButton("确认");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String s1=textField.getText();
				if(s1 == null || s1.isEmpty()){
					JOptionPane.showMessageDialog(null, "输入的学号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
				}else {
					JDBCutil jdbc=new JDBCutil();
					String sql="update student_change set CODE=? where 学号=?";	
					String s2=(String)comboBox.getSelectedItem();
					String s3=textField.getText();
					jdbc.testUpdate(sql, s2,s3);
					JOptionPane.showMessageDialog(null, "恭喜修改成功!", "信息", JOptionPane.INFORMATION_MESSAGE);
				}
				
			}
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button.setBounds(117, 190, 93, 42);
		contentPane.add(button);
		
		JButton button_1 = new JButton("退出");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "你已成功退出!", "信息", JOptionPane.INFORMATION_MESSAGE);
				dispose();
			}
		});
		button_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button_1.setBounds(351, 190, 93, 42);
		contentPane.add(button_1);
	}
}
package com.itheima.jdbc;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Color;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;

/**
* @author 罗志刚
* @date 2019年12月25日 下午2:26:04
* @Description   
*/
@SuppressWarnings("serial")
public class StudentSelect extends JFrame {
	JDBCutil query = new JDBCutil();// 创建数据库的操作类对象,用于数据库的各种操作
	public int flag=1;
	private JPanel contentPane;
	private JTextField textField;


	/**
	 * Create the frame.
	 */
	public StudentSelect() {
		setFont(new Font("微软雅黑", Font.PLAIN, 14));
		setTitle("查询界面");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 607, 391);
		contentPane = new JPanel();
		contentPane.setBackground(Color.CYAN);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		setLocationRelativeTo(null);//将窗口居中
		
		JLabel lblNewLabel = new JLabel("请选择要查询的方式");
		lblNewLabel.setForeground(Color.BLUE);
		lblNewLabel.setBackground(Color.WHITE);
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 23));
		lblNewLabel.setBounds(189, 23, 216, 31);
		contentPane.add(lblNewLabel);
		
		JRadioButton rdbtnNewRadioButton = new JRadioButton("按学号查询");
		rdbtnNewRadioButton.setBackground(Color.CYAN);
		rdbtnNewRadioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag=1;
			}
		});
		rdbtnNewRadioButton.setSelected(true);
		rdbtnNewRadioButton.setFont(new Font("微软雅黑", Font.BOLD, 18));
		rdbtnNewRadioButton.setBounds(92, 82, 121, 23);
		contentPane.add(rdbtnNewRadioButton);
		
		JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("按班级查询");
		rdbtnNewRadioButton_1.setBackground(Color.CYAN);
		rdbtnNewRadioButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag=2;
			}
		});
		rdbtnNewRadioButton_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		rdbtnNewRadioButton_1.setBounds(92, 126, 121, 23);
		contentPane.add(rdbtnNewRadioButton_1);
		
		JRadioButton rdbtnNewRadioButton_2 = new JRadioButton("按姓名查询");
		rdbtnNewRadioButton_2.setBackground(Color.CYAN);
		rdbtnNewRadioButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag=3;
			}
		});
		rdbtnNewRadioButton_2.setFont(new Font("微软雅黑", Font.BOLD, 18));
		rdbtnNewRadioButton_2.setBounds(92, 170, 121, 23);
		contentPane.add(rdbtnNewRadioButton_2);
		
		JRadioButton rdbtnNewRadioButton_3 = new JRadioButton("按专业查询");
		rdbtnNewRadioButton_3.setBackground(Color.CYAN);
		rdbtnNewRadioButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				flag=4;
			}
		});
		rdbtnNewRadioButton_3.setFont(new Font("微软雅黑", Font.BOLD, 18));
		rdbtnNewRadioButton_3.setBounds(92, 216, 121, 23);
		contentPane.add(rdbtnNewRadioButton_3);
		
		JButton btnNewButton = new JButton("确认");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
					if(flag==1) {
						String sql2 = "select *from student where 学号='"+textField.getText().trim()+"'";
						ResultSet rs2 = query.query(sql2);// 调用数据库的查询方法
						if(textField.getText() == null || textField.getText().isEmpty()) {
							JOptionPane.showMessageDialog(null, "输入的学号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						}else {
							@SuppressWarnings("unused")
							StudntInformationSelect select=new StudntInformationSelect(rs2);
						}											
					}else if(flag==2) {
						String sql2 = "select *from student where 班级='"+textField.getText().trim()+"'";
						ResultSet rs2 = query.query(sql2);// 调用数据库的查询方法
						if(textField.getText() == null || textField.getText().isEmpty()) {
							JOptionPane.showMessageDialog(null, "输入的班级不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						}else {
							@SuppressWarnings("unused")
							StudntInformationSelect select=new StudntInformationSelect(rs2);
						}											
					}else if(flag==3) {
						String sql2 = "select *from student where 姓名='"+textField.getText().trim()+"'";
						ResultSet rs2 = query.query(sql2);// 调用数据库的查询方法
						if(textField.getText() == null || textField.getText().isEmpty()) {
							JOptionPane.showMessageDialog(null, "输入的姓名不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						}else {
							@SuppressWarnings("unused")
							StudntInformationSelect select=new StudntInformationSelect(rs2);
						}											
					}else if(flag==4) {
						String sql2 = "select *from student where 专业='"+textField.getText().trim()+"'";
						ResultSet rs2 = query.query(sql2);// 调用数据库的查询方法
						if(textField.getText() == null || textField.getText().isEmpty()) {
							JOptionPane.showMessageDialog(null, "输入的专业不能为空", "警告", JOptionPane.ERROR_MESSAGE);
						}else {
							@SuppressWarnings("unused")
							StudntInformationSelect select=new StudntInformationSelect(rs2);
						}											
					}			
			}
		});
		btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 18));
		btnNewButton.setBounds(163, 279, 93, 42);
		contentPane.add(btnNewButton);
		
		ButtonGroup group =  new ButtonGroup();
		group.add(rdbtnNewRadioButton);
		group.add(rdbtnNewRadioButton_1);
		group.add(rdbtnNewRadioButton_2);
		group.add(rdbtnNewRadioButton_3);
		
		textField = new JTextField();
		textField.setFont(new Font("微软雅黑", Font.BOLD, 15));
		textField.setBounds(258, 148, 239, 31);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JButton button = new JButton("退出");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button.setBounds(370, 279, 93, 42);
		contentPane.add(button);
		
		JButton btnNewButton_1 = new JButton("查询所有学生信息");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String sql2 = "select *from student";
				ResultSet rs2 = query.query(sql2);// 调用数据库的查询方法
					@SuppressWarnings("unused")
					StudntInformationSelect select=new StudntInformationSelect(rs2);
			}
		});
		btnNewButton_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
		btnNewButton_1.setBounds(219, 238, 186, 31);
		contentPane.add(btnNewButton_1);
	}
}
package com.itheima.jdbc;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JMenu;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

/**
* @author 罗志刚
* @date 2019年12月23日 下午8:09:39
* @Description   
*/
@SuppressWarnings("serial")
public class StudentViews extends JFrame {

	@SuppressWarnings("unused")
	private JPanel contentPane;

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

	/**
	 * Create the frame.
	 */
	public StudentViews() {
		getContentPane().setFont(new Font("微软雅黑", Font.PLAIN, 14));
		setBackground(Color.RED);
		setForeground(Color.BLUE);
		setFont(new Font("微软雅黑", Font.PLAIN, 15));
		setTitle("学生信息管理系统");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 544, 374);
		setLocationRelativeTo(null);//将窗口居中
		getContentPane().setLayout(null);
		
		JMenuBar menuBar = new JMenuBar();
		menuBar.setBounds(0, 0, 350, 40);
		getContentPane().add(menuBar);
		
		JMenu mnNewMenu = new JMenu("学生个人信息录入");
		mnNewMenu.setForeground(Color.LIGHT_GRAY);
		mnNewMenu.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				InformationInput frame = new InformationInput();
				frame.setVisible(true);
			}
		});
		mnNewMenu.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		menuBar.add(mnNewMenu);
		
		JMenu mnNewMenu_1 = new JMenu("个人信息的查看");
		mnNewMenu_1.setForeground(Color.LIGHT_GRAY);
		mnNewMenu_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				StudentSelect frame = new StudentSelect();
				frame.setVisible(true);
			}
		});
		mnNewMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		menuBar.add(mnNewMenu_1);
		
		JMenu menu = new JMenu("个人信息的修改");
		menu.setForeground(Color.LIGHT_GRAY);
		menu.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				InformationRepair frame = new InformationRepair();
				frame.setVisible(true);
			}
		});
		menu.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		menuBar.add(menu);
		
		JButton button = new JButton("退出");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button.setBounds(1057, 10, 93, 42);
		getContentPane().add(button);
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(StudentViews.class.getResource("/ico/u=2781215003,3095086959&fm=26&gp=0[1].jpg")));
		lblNewLabel.setBounds(0, 39, 532, 300);
		getContentPane().add(lblNewLabel);
		
		JButton button_1 = new JButton("退出");
		button_1.setForeground(Color.CYAN);
		button_1.setBackground(Color.LIGHT_GRAY);
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				JOptionPane.showMessageDialog(null, "恭喜你已安全退出!", "信息", JOptionPane.INFORMATION_MESSAGE);
				System.exit(0);				
			}
		});
		button_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button_1.setBounds(435, 0, 93, 40);
		getContentPane().add(button_1);
	}
}
package com.itheima.jdbc;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.*;
import javax.swing.JTable;
import java.awt.Font;
/**
 * 
* @author 罗志刚
* @date 2019年12月25日 上午8:34:50
* @Description
 */
@SuppressWarnings("serial")
public class StudntInformationSelect extends JFrame {
	JDBCutil query = new JDBCutil();// 创建数据库的操作类对象,用于数据库的各种操作
	//从数据库中取出信息
	//rowData用来存放行数据
	//columnNames存放列名
	@SuppressWarnings("rawtypes")
	Vector rowData,columnNames;
	JTable jt=null;
	JScrollPane jsp=null;

	//构造函数
		@SuppressWarnings({ "rawtypes", "unchecked" })
		public StudntInformationSelect(ResultSet rs){
			getContentPane().setFont(new Font("微软雅黑", Font.PLAIN, 14));
			setTitle("学生信息查询界面");
			setFont(new Font("微软雅黑", Font.PLAIN, 14));
		
			columnNames=new Vector();
			//设置列名
			columnNames.add("学号");
			columnNames.add("名字");
			columnNames.add("性别");
			columnNames.add("生日");
			columnNames.add("年龄");
			columnNames.add("籍贯");
			columnNames.add("院系");
			columnNames.add("专业");
			columnNames.add("班级");
			columnNames.add("电话");
			rowData = new Vector();
			//rowData可以存放多行,开始从数据库里取
			try {
				// 将查询获得的记录数据,转换成适合生成JTable的数据形式
				while(rs.next()){
					//rowData可以存放多行
					Vector hang=new Vector();
					hang.add(rs.getObject(1));
					hang.add(rs.getObject(2));
					hang.add(rs.getObject(3));
					hang.add(rs.getObject(4));
					hang.add(rs.getObject(5));
					hang.add(rs.getObject(6));
					hang.add(rs.getObject(7));
					hang.add(rs.getObject(8));
					hang.add(rs.getObject(9));
					hang.add(rs.getObject(10));					
					//加入到rowData
					rowData.add(hang);
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally{
					try {
						if(rs!=null){
						rs.close();
						}
					} catch (SQLException e) {
						e.printStackTrace();
					}
			}
			//初始化Jtable
			jt = new JTable(rowData,columnNames);
			jt.setFont(new Font("微软雅黑", Font.PLAIN, 14));
			//初始化 jsp
			jsp = new JScrollPane(jt);
			//把jsp放入到jframe
			getContentPane().add(jsp);
			this.setSize(935,366);
			this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			this.setVisible(true);
			setLocationRelativeTo(null);// 窗体居中显示
		}
}
package com.itheima.jdbc;

import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
 * 
* @author 罗志刚
* @date 2019年12月22日 下午6:13:18
* @Description
 */
@SuppressWarnings("serial")
public class TeacherViews extends JFrame {

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

	/**
	 * Create the frame.
	 */
	public TeacherViews() {
		getContentPane().setFont(new Font("微软雅黑", Font.PLAIN, 14));
		setBackground(Color.RED);
		setForeground(Color.BLUE);
		setFont(new Font("微软雅黑", Font.PLAIN, 15));
		setTitle("学生信息管理系统");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 540, 375);
		setLocationRelativeTo(null);//将窗口居中
		getContentPane().setLayout(null);
		
		JMenuBar menuBar = new JMenuBar();
		menuBar.setBounds(0, 0, 422, 36);
		getContentPane().add(menuBar);
		
		JMenu mnNewMenu_2 = new JMenu("学籍变更");
		mnNewMenu_2.setForeground(Color.LIGHT_GRAY);
		mnNewMenu_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				StudentChange frame = new StudentChange();
				frame.setVisible(true);
			}
		});
		mnNewMenu_2.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		menuBar.add(mnNewMenu_2);
		
		JMenu mnNewMenu_3 = new JMenu("奖学金评定");
		mnNewMenu_3.setForeground(Color.LIGHT_GRAY);
		mnNewMenu_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				Student_Reward frame = new Student_Reward();
				frame.setVisible(true);
			}
		});
		mnNewMenu_3.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		menuBar.add(mnNewMenu_3);
		
		JMenu mnNewMenu_4 = new JMenu("处罚记录");
		mnNewMenu_4.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				Student_Punish frame = new Student_Punish();
				frame.setVisible(true);
			}
		});
		mnNewMenu_4.setForeground(Color.LIGHT_GRAY);
		mnNewMenu_4.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		menuBar.add(mnNewMenu_4);
		
		JMenu mnNewMenu_6 = new JMenu("学生情况查询");
		mnNewMenu_6.setForeground(Color.LIGHT_GRAY);
		mnNewMenu_6.addMouseListener(new MouseAdapter() {//鼠标点击事件
			@Override
			public void mouseClicked(MouseEvent arg0) {
				StudentSelect frame = new StudentSelect();
				frame.setVisible(true);
			}
		});
		mnNewMenu_6.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		menuBar.add(mnNewMenu_6);
		
		JMenu menu = new JMenu("学生信息删除");
		menu.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				Delete frame = new Delete();
				frame.setVisible(true);
			}
		});
		menu.setForeground(Color.LIGHT_GRAY);
		menu.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		menuBar.add(menu);
		
		JButton button = new JButton("退出");
		button.setForeground(Color.CYAN);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "恭喜你已安全退出!", "信息", JOptionPane.INFORMATION_MESSAGE);
				System.exit(0);	
			}
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 18));
		button.setBounds(432, 0, 93, 40);
		getContentPane().add(button);
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		lblNewLabel.setIcon(new ImageIcon(TeacherViews.class.getResource("/ico/u=3124827981,3461964212&fm=26&gp=0[1].jpg")));
		lblNewLabel.setBounds(0, 38, 525, 300);
		getContentPane().add(lblNewLabel);

	}
}

图片我就不发了,自己去网上随便找一点贴上去。

有问题联系我:qq:2483762760

发布了29 篇原创文章 · 获赞 3 · 访问量 409

猜你喜欢

转载自blog.csdn.net/dwjdj/article/details/103809303