📄 allquery.java
字号:
String values[]={"","男","女"};
JComboBox cmbSex = new JComboBox(values);
JLabel jLabel10 = new JLabel();
String zhengshu[]={"","S1","S2","Y2"};
JComboBox cmbzhengshu = new JComboBox(zhengshu);
JLabel jLabel11 = new JLabel();
String status[]={"","在读","休学","退学","转学","结业","毕业"};
JComboBox cmbStart = new JComboBox(status);
JLabel jLabel12 = new JLabel();
JLabel jLabel13 = new JLabel();
JTextField txtScore = new JTextField();
JLabel jLabel14 = new JLabel();
JTextArea txaRemark = new JTextArea();
JButton btnExit = new JButton();
JButton btnQuery = new JButton();
JTextField txtStudentNo = new JTextField();
JTextField txtClassNo = new JTextField();
JButton btnshuaxin = new JButton();
public void btnQuery_actionPerformed(ActionEvent e) {
try {
String sql = "select ClassInfo.Term,ClassInfo.ClassNo,StudentInfo.StudentNo,StudentInfo.Name,StudentInfo.Sex,StudentInfo.Birthday,StudentInfo.Address,StudentInfo.dianhua,StudentInfo.xueli,StudentInfo.Certificate,StudentInfo.Status,Score.Course,Score.Score,Score.Remark from ClassInfo join StudentInfo on ClassInfo.ClassNo = StudentInfo.ClassNo join Score on StudentInfo.StudentNo=Score.StudentNo where 1=1";
//if (!this.cmbTerm.getSelectedItem().toString().equals("")) {
//sql += " and ClassInfo.Term = '" +
// this.cmbTerm.getSelectedItem().toString() + "'";
//}
if (!this.txtClassNo.getText().equals("")) {
sql += " and ClassInfo.ClassNo like '%" + this.txtClassNo.getText() +
"%'";
}
if (!this.txtStudentNo.getText().equals("")) {
sql += " and StudentInfo.StudentNo like '%" + this.txtStudentNo.getText() +
"%'";
}
if (!this.txtName.getText().equals("")) {
sql += " and StudentInfo.Name like '%" + this.txtName.getText() +
"%'";
}
//if (!this.cmbSex.getSelectedItem().toString().equals("")) {
//sql += " and StudentInfo.Sex = '" +
//this.cmbSex.getSelectedItem().toString() + "'";
// }
if (!this.txtBirthday.getText().equals("")) {
sql += " and StudentInfo.Birthday = '" +
this.txtBirthday.getText() + "'";
}
if (!this.txtAddress.getText().equals("")) {
sql += " and StudentInfo.Address = '" +
this.txtAddress.getText() + "'";
}
if (!this.txtDianhua.getText().equals("")) {
sql += " and StudentInfo.dianhua = '" +
this.txtDianhua.getText() + "'";
}
/*if (!this.cmbXueli.getSelectedItem().toString().equals("")) {
sql += " and StudentInfo.xueli ='" +
this.cmbXueli.getSelectedItem().toString() + "'";
}
if (!this.cmbzhengshu.getSelectedItem().toString().equals("")) {
sql += " and StudentInfo.Certificate ='" +
this.cmbzhengshu.getSelectedItem().toString() + "'";
}
if (!this.cmbStart.getSelectedItem().toString().equals("")) {
sql += " and StudentInfo.Status ='" +
this.cmbStart.getSelectedItem().toString() + "'";
}*/
if (!this.txtCourse.getText().equals("")) {
sql += " and Score.Course = '" +
this.txtCourse.getText() + "'";
}
if (!this.txtScore.getText().equals("")) {
sql += " and Score.Score = '" +
this.txtScore.getText() + "'";
}
if (!this.txaRemark.getText().equals("")) {
sql += " and Score.Remark = '" + this.txaRemark.getText() +
"'";
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:xiangmu");
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
bg.setRowCount(0);
while (rs.next()) {
Object val[] = {rs.getString(1), rs.getString(2),rs.getString(3), rs.getString(4), rs.getString(5),rs.getString(6),
rs.getString(7), rs.getString(8), rs.getString(9),rs.getString(10), rs.getString(11),rs.getString(12), rs.getString(13), rs.getString(14)
};
bg.addRow(val);
}
jTable1.updateUI();
rs.close();
ps.close();
conn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void jTable1_mouseClicked(MouseEvent e) {
int row = this.jTable1.getSelectedRow();
if (row > -1) {
this.cmbTerm.setSelectedItem(this.jTable1.getValueAt(row, 0).
toString());
this.txtClassNo.setText(this.jTable1.getValueAt(row, 1).toString());
this.txtStudentNo.setText(this.jTable1.getValueAt(row, 2).toString());
this.txtName.setText(this.jTable1.getValueAt(row, 3).toString());
this.cmbSex.setSelectedItem(this.jTable1.getValueAt(row, 4).
toString());
//this.cmbSex.setSelectedItem(this.jTable1.getValueAt(row, 3).
//toString());
this.txtBirthday.setText(this.jTable1.getValueAt(row, 5).toString());
this.txtAddress.setText(this.jTable1.getValueAt(row, 6).toString());
this.txtDianhua.setText(this.jTable1.getValueAt(row, 7).toString());
this.cmbXueli.setSelectedItem(this.jTable1.getValueAt(row, 8).
toString());
this.cmbzhengshu.setSelectedItem(this.jTable1.getValueAt(row, 9).
toString());
this.cmbStart.setSelectedItem(this.jTable1.getValueAt(row, 10).
toString());
this.txtCourse.setText(this.jTable1.getValueAt(row, 11).toString());
this.txtScore.setText(this.jTable1.getValueAt(row, 12).toString());
this.txaRemark.setText(this.jTable1.getValueAt(row, 13).toString());
}
}
public void btnExit_actionPerformed(ActionEvent e) {
if (JOptionPane.showConfirmDialog(this, "是否确定退出综合信息查询", "温馨提示",
JOptionPane.OK_CANCEL_OPTION) ==
JOptionPane.OK_OPTION) {
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
this.dispose();
}
}
public void btnshuaxin_actionPerformed(ActionEvent e) {
this.cmbTerm.setSelectedItem("");
this.txtClassNo.setText("");
this.txtName.setText("");
this.txtStudentNo.setText("");
this.cmbSex.setSelectedItem("");
this.txtBirthday.setText("");
this.txtAddress.setText("");
this.txtDianhua.setText("");
this.cmbXueli.setSelectedItem("");
this.cmbzhengshu.setSelectedItem("");
this.cmbStart.setSelectedItem("");
this.txtCourse.setText("");
this.txtScore.setText("");
this.txaRemark.setText("");
}
}
class AllQuery_btnshuaxin_actionAdapter implements ActionListener {
private AllQuery adaptee;
AllQuery_btnshuaxin_actionAdapter(AllQuery adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnshuaxin_actionPerformed(e);
}
}
class AllQuery_btnExit_actionAdapter implements ActionListener {
private AllQuery adaptee;
AllQuery_btnExit_actionAdapter(AllQuery adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnExit_actionPerformed(e);
}
}
class AllQuery_jTable1_mouseAdapter extends MouseAdapter {
private AllQuery adaptee;
AllQuery_jTable1_mouseAdapter(AllQuery adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jTable1_mouseClicked(e);
}
}
class AllQuery_btnQuery_actionAdapter implements ActionListener {
private AllQuery adaptee;
AllQuery_btnQuery_actionAdapter(AllQuery adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnQuery_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -