Android中Cursor类的getColumnIndex()方法的用法

Android中Cursor类的getColumnIndex()方法的用法,第1张

在Android开发中,对SQLite数据库的 *** 作是通过cursor实现的,cursor 是每行数据的集合。

Cursor类的getColumnIndex方法():

getColumnIndex(String columnName) —— 返回列名为columnName对应的列索引(索引从0开始),如果不存在返回-1


对于SQLite数据库中的这张表,进行如下 *** 作:

int index = cursor.getColumnIndex("id");
int indexId = cursor.getColumnIndex("_id");
int indexName = cursor.getColumnIndex("name");
int indexPhone = cursor.getColumnIndex("phone");
int indexPath = cursor.getColumnIndex("image_path");

对应的的返回值为:

index = -1(因为不存在列名为"id"的列)indexId = 0indexName = 1indexPhone = 2indexPath = 3

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/992380.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存