科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道JAVA基础应用: 单机版管理系统源代码 (3)

JAVA基础应用: 单机版管理系统源代码 (3)

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

JAVA基础应用: 单机版管理系统源代码 (3)

作者:jettang 来源:CN-JAVA 2007年11月18日

关键字: java

  • 评论
  • 分享微博
  • 分享邮件
//////////////////////////////////////////////////提交删除
if (e.getSource() == toolBarButton[6] ||
e.getSource() == subMenu2[6]) {
if ((classidT.getText().trim()).equals("") ||
(nameT.getText().trim()).equals("") ||
(sexT.getText().trim()).equals("") ||
(ageT.getText().trim()).equals("") ||
(callT.getText().trim()).equals("") ||
(departmentT.getText().trim()).equals("")) {
JOptionPane.showMessageDialog(null, "请先点击删除键");
return;
} else {
name = nameT.getText();
String strSQL = "delete from stuinfo where name='" + name +
"'";
try {
st.executeUpdate(strSQL);
} catch (Exception exx) {
JOptionPane.showMessageDialog(null, "删除失败");
return;
}
JOptionPane.showMessageDialog(null, "删除成功");
classidT.setText("");
nameT.setText("");
sexT.setText("");
ageT.setText("");
callT.setText("");
departmentT.setText("");

}
}

//////////////////////////////////////////////集体查询(按班级)
if (e.getSource() == subMenu3[0]) {
classidT.setText("");
nameT.setText("");
sexT.setText("");
ageT.setText("");
callT.setText("");
departmentT.setText("");

if ((classidT.getText().trim()).equals("")) {
String idclass = JOptionPane.showInputDialog("请输入班级");
String strSQL = "select * from stuinfo where classid='" +
idclass +
"'";
try {
rs = st.executeQuery(strSQL);
displayres(rs);

} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "查询失败");
}

} else {
String idclass = classidT.getText();
String strSQL = "select * from stuinfo where classid='" +
idclass +
"'";
try {
rs = st.executeQuery(strSQL);
displayres(rs);
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "查询失败");
}
}
}
////////////////////////////按单位
if (e.getSource() == subMenu3[1]) {
classidT.setText("");
nameT.setText("");
sexT.setText("");
ageT.setText("");
callT.setText("");
departmentT.setText("");

if ((departmentT.getText().trim()).equals("")) {
String idclass = JOptionPane.showInputDialog("请输入单位");
String strSQL = "select * from stuinfo where department='" +
idclass +
"'";
try {
rs = st.executeQuery(strSQL);
displayres(rs);

} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "查询失败");
}

} else {
String idclass = departmentT.getText();
String strSQL = "select * from stuinfo where department='" +
idclass +
"'";
try {
rs = st.executeQuery(strSQL);
displayres(rs);
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "查询失败");
}
}
}
}

public void displayres(ResultSet rs1) throws SQLException {
//定位到达第一条记录
boolean moreRecords = rs1.next();

//如果没有记录,则提示一条消息

if (!moreRecords) {

JOptionPane.showMessageDialog(null, "无此记录");

return;

}
try {

//获取数据
getNextRow(rs1);

//刷新Table
c.validate();

}

catch (SQLException sqlex) {

sqlex.printStackTrace();

}
}

public void getNextRow(ResultSet rs2) throws
SQLException {
int count = 1;
while (rs2.next()) {
name = " 姓名:" + rs2.getString(1);
age = " 年龄:" + rs2.getString(2) + " 单位:";
department = rs2.getString(3) + "\n";
textT.append(count + "." + name + age + department);
count++;
}
}
}查看本文来源
    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章