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

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

 2010-11-05 00:56:30 来源:WEB开发网   
核心提示:autoincrement,name varchar(20),age integer)");}@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVewsion) {Log.i("aa",&quo
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);

}

}

新建一个service服务类:

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();

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

try {

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

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

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

}

db.execSQL("insert into personww(namedd,age) values(?,?)",

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

db.setTransactionSuccessful();

} catch (Exception e) {

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

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

}

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

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

}

public void save1(Person person) {

SQLiteDatabase db = databaseHelper.getWritableDatabase();

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

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

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

Tags:android SQLite 数据库

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接