samedi 2 avril 2016

Java SQLite JDBC executeQuery returns empty ResultSet of a non-empty column

My code:

Class.forName("org.sqlite.JDBC");
Connection C = DriverManager.getConnection("jdbc:sqlite:test.db");

Statement S = C.createStatement();
S.execute("CREATE TABLE NUMBER (VALUE INT(1))");
S.close();

S = C.createStatement();
S.execute("UPDATE NUMBER SET VALUE = 0");
S.close();

Statement S = C.createStatement();
ResultSet Value = S.executeQuery("SELECT VALUE FROM NUMBER");

if(Value.next())
{

    int Result = Value.getInt("VALUE");
    System.out.println("Success");

}
else
{

    System.out.println("Failure");

}

S.close();

I would expect the result of this code would be "Success", because it should retrieve the integer value 0 from the column VALUE in the table NUMBER. However, it instead prints "Failure". I cannot figure out if this is because the table is actually empty or because it just can't get the data or what. Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire