1.系统需求分析
1.1 IC卡读写板
IC卡读写板可以把IC卡的信息读出来,也可以往里面写信息。
1.2 IC卡
2. 系统总体设计
3.java开发系统界面
public void showData() {
String sql = "select * from record";
// 数据库访问
DBUtil1 db = new DBUtil1();
try {
db.getConnection("entering");
ResultSet rs = db.executeQuery(sql, null);
ResultSetMetaData rsmd = rs.getMetaData();
// 获取列数
int colCount = rsmd.getColumnCount();
// 存放列名
Vector<String> title = new Vector<String>();
// 列名
for (int i = 1; i <= colCount; i++) {
title.add(rsmd.getColumnLabel(i));
}
// 表格数据
Vector<Vector<String>> data = new Vector<Vector<String>>();
int rowCount = 0;
while (rs.next()) {
rowCount++;
// 行数据
Vector<String> rowdata = new Vector<String>();
for (int i = 1; i <= colCount; i++) {
rowdata.add(rs.getString(i));
}
data.add(rowdata);
}
if (rowCount == 0) {
model.setDataVector(null, title);
} else {
model.setDataVector(data, title);
}
} catch (Exception ee) {
System.out.println(ee.toString());
JOptionPane.showMessageDialog(this, "系统出现异常错误。请检查数据库。系统即将退出!!!",
"错误", 0);
} finally {
db.closeAll();
}
}
public void deleteData() {
int index[] = table_1.getSelectedRows();
if (index.length == 0) {
JOptionPane.showMessageDialog(this, "请选择要删除的记录", "提示",
JOptionPane.PLAIN_MESSAGE);
} else {
try {
int k = JOptionPane.showConfirmDialog(this,
"您确定要从数据库中删除所选的数据吗 ?", "删除", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (k == JOptionPane.YES_OPTION) {
DBUtil1 db = new DBUtil1();
try {
db.getConnection("entering");
String name = table_1.getValueAt(index[0], 1).toString();
String sql = "delete from record where name=?";
int count = db.executeUpdate(sql, new String[] {
name});
if (count == 1) {
JOptionPane.showMessageDialog(this, "删除操作成功完成!",
"成功", JOptionPane.PLAIN_MESSAGE);
showData();
} else {
JOptionPane.showMessageDialog(this, "抱歉! 删除数据失败!",
"失败:", 0);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
db.closeAll();
}
}
} catch (Exception ee) {
JOptionPane.showMessageDialog(this, "抱歉!删除数据失败!【系统异常!】", "失败:",
0);
}
}
}
public void insertData() {
int i=model.getRowCount();
model.addRow(new Vector());
}
protected void saveData() {
int i=model.getRowCount();
DBUtil1 db = new DBUtil1();
try {
db.getConnection("entering");
String rfidno = table_1.getValueAt(i-1, 0).toString();
String name = table_1.getValueAt(i-1, 1).toString();
String gender = table_1.getValueAt(i-1, 2).toString();
String record = table_1.getValueAt(i-1, 3).toString();
String money = table_1.getValueAt(i-1, 4).toString();
String phoneno = table_1.getValueAt(i-1, 5).toString();
String time = table_1.getValueAt(i-1, 6).toString();
String sql = "insert into record values('"+rfidno+"','"+name+"','"+
gender+"','"+record+"','"+money+"','"+phoneno+"','"+time+"')";
int count = db.executeUpdate(sql, null);
if (count == 1) {
JOptionPane.showMessageDialog(this, "保存操作成功完成!",
"成功", JOptionPane.PLAIN_MESSAGE);
showData();
} else {
JOptionPane.showMessageDialog(this, "抱歉! 保存数据失败!",
"失败:", 0);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
db.closeAll();
}
}