我已尝试过这个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();
答案 0 :(得分:2)
这样有效吗?不久前我遇到了同样的问题,结果表明数据类型在表中被声明为CHAR
(而不是NUMERIC
等)。
这可能会导致一些并发症,起初可能并不明显。例如,声明为CHAR的列可能具有前导或尾随空格(例如:'1'或'1'),这可能会在数据类型转换过程中造成麻烦。