Reputation: 613
public Cursor getBiggestInTheColumn()
{
return db.query(HEADER_TABLE, null,"MAX(key_Division)", null, null, null, null);
}
and I call this method as Cursor cc=db.getBiggestInTheColumn();
But it forcefully close the application.Please help me
Upvotes: 3
Views: 15449
Reputation: 641
public int getBiggestInTheColumn()
{
Cursor c = db.query(HEADER_TABLE, null,new String[] {"MAX(key_Division)"}, null, null, null, null);
try {
c.moveToFirst();
return c.getInt(0);
} finally {
c.close();
}
}
Upvotes: 5
Reputation: 7889
You can use simpleQueryForLong
and cast it accordingly.
public int getMaxColumnData() {
mDb = mDbManager.getReadableDatabase();
final SQLiteStatement stmt = mDb
.compileStatement("SELECT MAX(column) FROM Table");
return (int) stmt.simpleQueryForLong();
}
Upvotes: 25