在android中按名字的字母顺序从表中提取数据
我在执行下面给出的查询时遇到了一个sqlite异常在android中按名字的字母顺序从表中提取数据,android,Android,我在执行下面给出的查询时遇到了一个sqlite异常 Cursor c=db.query("patient_tbl", new String[] {" first_name"}, null, null, null, null,"DESC"); 例外情况是: 08-19 16:55:35.748: E/AndroidRuntime(2808):android.database.sqlite.SQLiteException: no such column: DESC: , whil
Cursor c=db.query("patient_tbl", new String[] {" first_name"},
null, null, null, null,"DESC");
例外情况是:
08-19 16:55:35.748: E/AndroidRuntime(2808):android.database.sqlite.SQLiteException:
no such column: DESC: , while compiling: SELECT first_name FROM patient_tbl
ORDER BY DESC
db.query
中的最后一个参数是orderBy
,它说明如何对行进行排序,格式为SQL order BY子句(不包括order本身)。因此,您还必须提及列名
您刚才提到了DESC
,这样您就不会得到这样的列
SQLiteException
所以使用
Cursor c=db.query("patient_tbl", null,
null, null, null, null,"first_name ");
我改为这个游标c=db.query(“patient_tbl”,null,null,null,null,null,“first_name”);现在可以了。通过使用上面的代码,我得到了08-19 17:16:36.148:E/AndroidRuntime(3744):java.lang.IllegalStateException:无法从CursorWindow读取第0行第1列。在从光标访问数据之前,请确保光标已正确初始化。