WEB开发网
开发学院手机开发Android 开发 android SQLite数据库的增删改查以及事务的单元测... 阅读

android SQLite数据库的增删改查以及事务的单元测试

 2010-11-05 00:56:30 来源:WEB开发网   
核心提示:try {db.setTransactionSuccessful();db.execSQL("insert into person(name,age) values('Tom',21)");} catch (Exception e) {Log.i("aa", &q

try {

db.setTransactionSuccessful();

db.execSQL("insert into person(name,age) values('Tom',21)");

} catch (Exception e) {

Log.i("aa", "trttttttttttttttttttttttttttttttttttttttttttttt");

}

db.endTransaction();// 事务结束;

}

public void save2(Person person) {

SQLiteDatabase db = databaseHelper.getWritableDatabase();

db.beginTransaction();// 开始事务

Log.i("aa", "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu");

try {

db.setTransactionSuccessful();

for(int i=0;i< 100;i++){

db.execSQL("insert into person(name,age) values(?,?)",

new Object[] { person.getName(), person.getAge() });

}

} catch (Exception e) {

Log.i("aa", "trttttttttttttttttttttttttttttttttttttttttttttt");

}

db.endTransaction();// 事务结束;

}

public void update(Person person) {

SQLiteDatabase db = databaseHelper.getWritableDatabase();

db.execSQL(

"update person set name=?,age=? where personid=?",

new Object[] { person.getName(), person.getAge(),

person.getId() });

}

public Person find(Integer id) {

SQLiteDatabase db = databaseHelper.getReadableDatabase();

Cursor cursor = db.rawQuery(

"select personid,name,age from person where personid=?",

new String[] { String.valueOf(id) });

if (cursor.moveToNext()) {

Person person = new Person();

person.setId(cursor.getInt(cursor.getColumnIndex("personid")));

person.setName(cursor.getString(1));

person.setAge(cursor.getInt(2));

return person;

}

cursor.close();

return null;

}

public void delete(Integer id) {

SQLiteDatabase db = databaseHelper.getWritableDatabase();

上一页  1 2 3 4 5 6  下一页

Tags:android SQLite 数据库

编辑录入:coldstar [复制链接] [打 印]
赞助商链接