在sqlite中是否可以通过列名而不是索引来获取列数据?我不想依赖列的特定顺序。如果是这样,语法是什么?
最佳答案
您可能想使用 Cursor.getColumnIndex()方法。
Returns the zero-based index for the given column name, or -1 if the column doesn't exist. If you expect the column to exist use getColumnIndexOrThrow(String) instead, which will make the error more clear.
例子:
String[] columns = new String[]{ COLUMN_XML };
Cursor c = db.query(TABLE, columns, where, whereArgs, null, null, null);
String xml = c.getString(c.getColumnIndex(COLUMN_XML));
关于android如何通过列名获取sqlite数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13298685/