能用select max(id) from table吗?execSQL好像不能执行select语句,并且这个函数没有返回值,我想取得id的最大值存到一个变量里面,怎么弄啊,谢谢
------解决方案--------------------
ContentValue cv=new ConetValue();//这个cv里面什么也不放,把这个cv插入到数据库中就会返回_id
------解决方案--------------------
查询语句不是用execSQL,而是用另一个rawXXX的,返回的Cursor的变量,你可以谷歌下。
哎。。。,eclipse自动提示功能让程序员变弱智了
------解决方案--------------------
sqllite是支持max函数的
检查检查你的表数据和字段
------解决方案--------------------
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query("table_name", null, null, null, null, null, "ORDER BY ID DESC");
if(cursor.moveToNext()
{
int id = cursor.getInt(cursor.getColumnIndex("_id"));
// 这个id就是最大值
}
------解决方案--------------------
------解决方案--------------------
select max(_id) AS maxId from tableName
String strSql = "select max(_id) AS maxId from tableName";
Cursor mCursor = db.rawQuery(strSql, null);
int maxId = cursor.getInt(cursor.getColumnIndex(maxId));