然后运用moveToFirst,isAfterLast,moveToNext等方法查询
在Curesor中index是从0开始查询列数的
例子:
1.新建数据库SQliteOpenHelper类
package com.example.CursorDemo;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by Anonymous on 2016/1/19.
*/
public class OpenHelpClass extends SQLiteOpenHelper {
public OpenHelpClass(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table stu (id integer primary key autoincrement,name text not null,age text not null)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists stu");
onCreate(db);
}
}
2.插入数据方法类: