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

📄 inquryinfo.java

📁 简单的学生管理系统
💻 JAVA
字号:
package catking.home.love;
import javax.swing.*;
import java.sql.*;
import java.awt.*;

public class InquryInfo extends PrimaryKey{
	private Connection con;
	public InquryInfo(Connection con,String title,String info)
	{
		super(title,info);
		this.con = con;
	}
	@Override
	protected void isConfirm() {
		// TODO Auto-generated method stub
		if(tf.getText().length() != 10)
			JOptionPane.showMessageDialog(null,"输入栏不能为空");
		else
		{
			String[] strNames = {"SNO","SN","SEX","DEPT","AGE"};
			try {
				PreparedStatement ps = con.prepareStatement("SELECT * FROM S WHERE SNO=?");
				ps.setString(1,tf.getText());
				ResultSet rs = ps.executeQuery();
				
				//如果没有判断rs.next()将出错
				if(rs.next())
				{
					for(int i=0; i < strNames.length-1; ++i)
						strNames[i] = rs.getString(strNames[i]);
					strNames[4] = ""+ rs.getInt("AGE");
				}
				else
					throw new SQLException();
			} catch (SQLException e) {
				JOptionPane.showMessageDialog(null,"指定的记录不存在!");
				return;
			}
			final String[] items = {"编号","姓名","性别","系别","年龄"};
			JDialog infoDlg = new JDialog(this,true);
			infoDlg.setTitle("客户信息");
			infoDlg.setSize(400,400);
			infoDlg.setLayout(new GridLayout(5,1,0,4));
			for(int i =0; i < items.length; ++i)
			{
				JPanel p = new JPanel();
				//记录间隔开来,便于观察
				p.setBackground(i%2 == 0 ? Color.WHITE :Color.red);
				p.setLayout(new GridLayout(1,2,2,0));
				JLabel itemLb = new JLabel(items[i],SwingConstants.CENTER);
				JLabel infoLb = new JLabel(strNames[i],SwingConstants.CENTER);
				p.add(itemLb);
				p.add(infoLb);
				infoDlg.add(p);
			}
			infoDlg.setVisible(true);
		}
	}
	
}

⌨️ 快捷键说明

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