Android 在模拟器上显示数据库中提取的信息的列表
2010-11-05 00:56:33 来源:WEB开发网< /LinearLayout>
新建一个工具类DataBaseHaler.java:
package com.gohighsoft.db;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DataBaseHaler extends SQLiteOpenHelper {
private static final String NAME = "sharp.db";// 。db可有可无
private static final int version = 1;// 版本号不能为0
public DataBaseHaler(Context context) {
super(context, NAME, null, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.i("aa","1111111111111");
db.execSQL("CREATE TABLE person(personid integer primary key autoincrement,name varchar(20),age integer)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVewsion) {
Log.i("aa","22222222222222");
db.execSQL("DROP TABLE IF EXISTS PERSON");
onCreate(db);
}
}
新近一个PersonService.java的服务类:
package com.gohighsoft.db;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
public class PersonService {
private DataBaseHaler databaseHelper;
private Context context;
public PersonService(Context context) {
this.context = context;
databaseHelper = new DataBaseHaler(context);
}
public void savesTrannces(Person person) {
Log.i("aa", "4444444444444");
SQLiteDatabase db = databaseHelper.getWritableDatabase();
更多精彩
赞助商链接