我有这样的查询
SELECT value1 FROM mytable where (value1 > value2) AND category = 1 ;
这在Android中无法正常执行。虽然如果我手动去
/data/data/packagename/databases/mydatabase.db
这是代码
try {
SQLiteDatabase sqdb = _context.openOrCreateDatabase(_DB_NAME, 0,
null);
String sql = null;
sql = "SELECT value1 FROM mytable where (value1 > value2) AND category = " + category
+"; ";
Cursor c = sqdb.rawQuery(sql, null);
Log.i("sql = ", sql);
if (c.moveToFirst()) {
while (!c.isAfterLast()) {
categoryValue = c.getString(0);
c.moveToNext();
}
}
Log.i("categoryValue", categoryValue);
sqdb.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
然后执行它。然后它完全正常。
发生了什么事?
答案 0 :(得分:1)
我相信首先需要关闭游标,然后关闭数据库连接
//the order should be
c.close();
sqdb.close();