我按照你那DateBaseCls里的方法重写了个方法,可是当我打印这个数组时却是空的,不知道为什么!
我的代码如下:
public static ArrayList getCardId(Record record, EndRecordComputer eRecord,
Card card) {
ArrayList endCardIdList = new ArrayList();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ce) {
JOptionPane.showMessageDialog(null, ce, "错误",
JOptionPane.ERROR_MESSAGE);
}
try {
String url = "jdbc:odbc:NetBar";
String str = "select * from Record where Computer='" +
eRecord.getEndComputer() + "'";
Connection con = DriverManager.getConnection(url, "Record",
"123456");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery(str);
while (rs.next()) {
record.setCardId(rs.getString("CardId"));
record.setComputerId(rs.getString("Computer"));
record.setBeginTime(rs.getString("BeginTime"));
record.setEndTime(rs.getString("EndTime"));
endCardIdList.add(record);
}
s.close();
con.close();
} catch (SQLException se) {
JOptionPane.showMessageDialog(null, se + "121212121212", "错误",
JOptionPane.ERROR_MESSAGE);
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ce) {
JOptionPane.showMessageDialog(null, ce, "错误",
JOptionPane.ERROR_MESSAGE);
}
try {
String url = "jdbc:odbc:NetBar";
String str = "select * from Card where Id='" +
eRecord.getEndComputer() + "'";
Connection con = DriverManager.getConnection(url, "Card",
"123456");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery(str);
while (rs.next()) {
card.setId(rs.getString("Id"));
card.setPassword(rs.getString("Password"));
card.setBalance(rs.getInt("balance"));
card.setUserName(rs.getString("UserName"));
endCardIdList.add(card);
}
s.close();
con.close();
} catch (SQLException se) {
JOptionPane.showMessageDialog(null, se + "101010", "错误",
JOptionPane.ERROR_MESSAGE);
}
return endCardIdList;
}
这个代码里的数组为什么会是空的啊?