jdbc sqlite不返回任何行

时间:2015-03-01 12:40:27

标签: java sqlite jdbc

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;
}

为什么我没有返回任何行?我正在使用这个连接:

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;
 } }  

运行SQLite Studio时,我的查询会返回正确的结果,但是我在控制台上的输出是:

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

0 个答案:

没有答案