【问题标题】:How To KnowTable Count in Sqlite Black Berry如何知道 Sqlite Blackberry 中的表数
【发布时间】:2011-06-20 20:28:31
【问题描述】:

谁能告诉我如何计算黑莓sqlite中的表记录数。

谢谢

【问题讨论】:

  • 从表中选择count(Primarykey);

标签: sqlite blackberry


【解决方案1】:

其实 Count(0) 也是在耍花招,要得到结果,它是 cursor 中的第一行也是唯一的一行,第一个字段,输入 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;
    }

【讨论】:

    猜你喜欢
    • 2023-03-06
    • 2021-06-18
    • 2018-12-03
    • 1970-01-01
    • 2019-05-10
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    相关资源
    最近更新 更多