我已经用这个 SQLite 语句尝试了我能想到的一切。我有以下要运行的代码。
public ArrayList getData(int i)
{
data = new ArrayList();
try
{
Statement stat2;
stat2 = conn.createStatement();
System.out.println(i);
PreparedStatement prep9 = conn.prepareStatement("SELECT * FROM tbl_INPUT_OBJECTS WHERE cardID = ?;");
prep9.setInt(1, i);
ResultSet rs2 = prep9.executeQuery();
while (rs2.next())
{
System.out.println(3);
IOdevice.get("IOdevice" + (rs2.getInt("id") - (16 * (i - 1)))).setId(rs2.getInt("id") - (16 * (i - 1)));
IOdevice.get("IOdevice" + (rs2.getInt("id") - (16 * (i - 1)))).setDescription(rs2.getString("description"));
System.out.println(4);
System.out.println(rs2.getString("description"));
System.out.println(rs2.getInt("id") - (16 * (i - 1)));
System.out.println(IOdevice.get("IOdevice" + (rs2.getInt("id") - (16 * (i - 1)))));
System.out.println(rs2.getBoolean("state"));
System.out.println(rs2.getString("type"));
System.out.println("IOdevice" + (rs2.getInt("id") - (16 * (i - 1))));
IOdevice.get("IOdevice" + (rs2.getInt("id") - (16 * (i - 1)))).setState(rs2.getBoolean("state"));
IOdevice.get("IOdevice" + (rs2.getInt("id") - (16 * (i - 1)))).setType(rs2.getString("type"));
}
rs2.close();
stat2.close();
System.out.println(5);
......etc.
我正在查看的数据库是这样的:
我这部分程序的输出是:
1
5
它应该是:
1
3
4
5
有人可以就我做错了什么给我建议吗?
注意:以下代码确实有效,因此它不是数据库本身......(至少我不认为它是。)
Statement stat;
stat = conn.createStatement();
ResultSet rs = stat
.executeQuery("SELECT * from tbl_TEST WHERE cardID = " + i
+ ";");
while (rs.next())
{
data.add(rs.getInt("id"));
data.add(rs.getString("lblDescriptionProp"));
data.add(rs.getString("lblAddressProp"));
data.add(IOdevice);
for (int j = 1; j <= 32; j++)
{
IOdevice.get("IOdevice" + j).getDescription();
IOdevice.get("IOdevice" + j).getState();
IOdevice.get("IOdevice" + j).getType();
}
}
rs.close();
stat.close();