能用select max(id)  from table吗?execSQL好像不能执行select语句,并且这个函数没有返回值,我想取得id的最大值存到一个变量里面,怎么弄啊,谢谢

解决方案 »

  1.   

    ContentValue cv=new ConetValue();//这个cv里面什么也不放,把这个cv插入到数据库中就会返回_id
      

  2.   

    查询语句不是用execSQL,而是用另一个rawXXX的,返回的Cursor的变量,你可以谷歌下。
    哎,eclipse自动提示功能让程序员变弱智了
      

  3.   

    sqllite是支持max函数的
    检查检查你的表数据和字段
      

  4.   

    select id from table order by id desc;得到结果的第一个就是ID的最大值;
      

  5.   

    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就是最大值
    }
      

  6.   

    那怎么从Cursor中得到我要的这个ID值呢?
      

  7.   


    Cursor c = ....String id = c.getString("_id", 0);
      

  8.   

    这个函数不对啊,public abstract String getString (int columnIndex) 
      

  9.   

    查询 表中的count总数 不就行了吗?
      

  10.   

    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));
      

  11.   

    楼上已经给出了正确答案
    max(_id)
      

  12.   


    嘿,你好,我使用上述代码的时候,出现了: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 异常,解决方法如下:Cursor mCursor = db.rawQuery(strSql, null);
    mCursor.moveToNext();
    int maxId = mCursor .getInt(mCursor.getColumnIndex(maxId)); 你没有遇到过该异常吗?另:如有错误,欢迎指出。
    Thanks.