Reputation: 47
I have tried everything that i can think of with this SQLite statement. i have the following code that I am trying to run.
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.
my database that i am looking at is this:
my output from this part of the program is:
1
5
it should be:
1
3
4
5
can anybody give me advice as to what I'm doing wrong?
NOTE: the following code does work so it is not the database itself...(At least I don't think it is.)
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();
Upvotes: 0
Views: 136
Reputation: 25966
So it works? I had the same problem not too long ago and it turned out the datatype was declared as CHAR
in the table (as opposed to NUMERIC
etc).
This can cause some complication, and it may not be obvious at first. For example a column declared as CHAR could have leading or trailing spaces (ex: ' 1' or '1 ') and this can spell trouble during data type conversion.
Upvotes: 2