dimanche 1 mars 2015

jdbc sqlite returns no rows


public ArrayList<Booking> getAllBookings(){
ArrayList<Booking> list = new ArrayList<Booking>();
int rowCount = 0;
try {
stmt = connection.createStatement();
String sql = "SELECT * FROM Bookings";
ResultSet rows = stmt.executeQuery(sql);
rows.last();
System.out.println("Row Count "+rows.getRow());
rows.beforeFirst();
connection.commit();

while (rows.next()){
Booking b = new Booking();
otherStuff();
list.add(b);
rowCount++;
}
stmt.close();
rows.close();
} catch (Exception e) {

}

System.out.println("There were " +rowCount + " records.");
return list;
}


Why do I not get any rows returned? I am connecting using this:



public static Connection dbConnect(){
try {
Class.forName("org.sqlite.JDBC");
Connection connection = DriverManager.getConnection("jdbc:sqlite:D:/test/test_db.sqlite3");
System.out.println("Connection Succesful");
return connection;
} catch (Exception e) {
System.out.println(e);
return null;
} }


When running SQLite Studio my query returns the correct results, but here my output on console is:



Connection Succesful
(Row Count + rows.getRow() is not printing here for some reason)
There were 0 records.

Aucun commentaire:

Enregistrer un commentaire