0
votes

Can any one tell me how to count table records in black berry sqlite.

Thank You

1
Select count(Primarykey) from table; - Jisson

1 Answers

1
votes

Actually Count(0) also doing a trick, and to get a result, it's the first and only row in cursor, first field, type int:

    public static int selectRecordsCount(String dbUrl, String tableName)
            throws DatabaseException, DataTypeException,
            IllegalArgumentException, MalformedURIException {
        int result = -1;
        URI myURI = URI.create(dbUrl);
        Database d = DatabaseFactory.open(myURI);
        Statement st = d.createStatement("SELECT COUNT(0) FROM "
                + String.valueOf(tableName));
        st.prepare();
        Cursor c = st.getCursor();
        c.next();
        result = c.getRow().getInteger(0);
        st.close();
        d.close();
        return result;
    }