SQL数据库是Android自带的轻型数据库,操作简单保存信息可靠。
实例:学生信息的管理
首先创建DataBaseHelper类继承SQLOpenHelper
package com.zhang.android;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by asus-pc on 2015/2/19.
*/
public class DataBaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "student.db";
private static final int DATABASE_VERSION = 1;
public DataBaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS student" +
"(_id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER, name VARCHAR, math FLOAT, geometry FLOAT, cProgram FLOAT)");
}
@Override
public void onUpgrade(SQLiteDa