lundi 10 août 2015

know how to get the total row count

i want to get the total row count in the sqlite DB, i referred to some posts and i wrote the below code, but at run time i receive xception in thread "main" java.sql.SQLException: SQLite only supports TYPE_FORWARD_ONLY cursors.

i chnages the parameter to be

stmt = conn.createStatement(
            ResultSet.TYPE_FORWARD_ONLY, 
            ResultSet.CONCUR_READ_ONLY);

but at run time i receive row count equals 0 despite there are rows in the DB.

kindly please let me know how to get the total row count correctly?

code:

public int getRowCount() throws SQLException, ClassNotFoundException {
    Connection conn = getConnection();
    Statement stmt = conn.createStatement();
    stmt = conn.createStatement(
            ResultSet.TYPE_SCROLL_SENSITIVE, 
            ResultSet.CONCUR_READ_ONLY);
    ResultSet resSet = stmt.executeQuery(this.selectRowCount);

    int size = 0;
    try {
        resSet.last();
        size = resSet.getRow();
        resSet.beforeFirst();
    }
    catch(Exception ex) {
        resSet.close();
        stmt.close();
        conn.close();

        Log.d(TAG, "", "RowCount: "+size);
        return 0;
    }

    resSet.close();
    stmt.close();
    conn.close();

    Log.d(TAG, "", "RowCount: "+size);
    return size;
}

Aucun commentaire:

Enregistrer un commentaire