⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 changepersoninformation.java

📁 管理学生信息
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
class ChangePersonInformation extends JFrame implements ActionListener
{
	String s;
	JButton ok,cancel;
	Choice text2,text3;
	JTextField text1;
	public ChangePersonInformation(String s){
		super("修改个人记录");
		this.s=s;
		setSize(500,300);
		setLayout(new GridLayout(4,1));
		setVisible(true);
		JPanel p[]=new JPanel[4];
		JLabel l[]=new JLabel[3];
		String k[]=new String[]{"新姓名","性别","出生年份"};
		for (int i=0;i<3 ;i++ )
		{
			l[i]=new JLabel(k[i]);
			p[i]=new JPanel();
			p[i].add(l[i]);
			add(p[i]);
		}
		text1=new JTextField(20);p[0].add(text1);
		text2=new Choice();p[1].add(text2);
		text2.addItem("男");
		text2.addItem("女");
		text3=new Choice();
		for(int i=1900;i<2099;i++)
			text3.addItem(String.valueOf(i));
		p[2].add(text3);
		p[3]=new JPanel();

		ok=new JButton("确定");
		cancel=new JButton("取消");
		p[3].add(cancel);
		p[3].add(ok);
		add(p[3]);
		cancel.addActionListener(this);
		ok.addActionListener(this);
		validate();
		pack();
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	public void actionPerformed(ActionEvent e){
		if (e.getSource()==ok)
		{
			Connection con=null;
			Statement sm=null;
			ResultSet rs=null;
			try{
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				con=DriverManager.getConnection("jdbc:odbc:student");
			}catch(Exception ex){System.out.println(ex.getMessage());}
			try{
				sm=con.createStatement();
				String command="update st set sname='"+text1.getText().trim()+"',sex='"+text2.getSelectedItem()+"',birth='"+text3.getSelectedItem()+"' where sno='"+s+"'";
				sm.executeUpdate(command);
				JOptionPane.showMessageDialog(this,"修改成功","修改成功",JOptionPane.WARNING_MESSAGE);
				sm.close();
				con.close();
			}catch(SQLException kk){System.out.println(kk.getMessage());}
		}
		else
			dispose();
		}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -