android SQLite数据库的增删改查以及事务的单元测试
2010-11-05 00:56:30 来源:WEB开发网废话少说,为了这个数据库整理一两天的时间,下面就把代码直接贴出来:
创建androidproject 名称:db
创建包名:com.gohighsoft.db
新建一个Person实体类:
package com.gohighsoft.db;
public class Person {
private Integer id;
private String name;
private Integer age;
public Person() {
};
public Person(String name, Integer age) {
this.name = name;
this.age = age;
}
public Integer getId(){
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String toString() {
return "Person [age=" + age + ",id=" + id + ",name" + name + "]";
}
}
新建工具类:
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
更多精彩
赞助商链接