Reputation: 14370
I have a query like this
SELECT value1 FROM mytable where (value1 > value2) AND category = 1 ;
This is not executing properly in Android. Although if i manually go to
/data/data/packagename/databases/mydatabase.db
Here is the Code
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();
}
And then execute it. Then it works perfectly fine.
What is happeneing?
Upvotes: 0
Views: 70
Reputation: 68187
i believe first you need to close cursor and then the database connection
//the order should be
c.close();
sqdb.close();
Upvotes: 1