【发布时间】:2011-06-20 20:28:31
【问题描述】:
谁能告诉我如何计算黑莓sqlite中的表记录数。
谢谢
【问题讨论】:
-
从表中选择count(Primarykey);
标签: sqlite blackberry
谁能告诉我如何计算黑莓sqlite中的表记录数。
谢谢
【问题讨论】:
标签: sqlite blackberry
其实 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;
}
【讨论】: