????// ===============SQLite??????????=====================

/**
* ??????????
*/
public void transation(){
db.beginTransaction();
try {
//name???????????С?????
ContentValues contentValues=new ContentValues();
contentValues.put("money"?? 1000);
db.update("person"?? contentValues?? "name=?"?? new String[]{"???"});
ContentValues contentValues2=new ContentValues();
contentValues2.put("money"?? 1100);
db.update("person"?? contentValues2?? "name=?"?? new String[]{"С??"});
//???????????????????????????????????????????????
db.setTransactionSuccessful();
} finally {
//?????????????????е???setTransactionSuccessful()??????????????????????????????
db.endTransaction();
}
}
}
MyOpenHelper.java
**SQLiteOpenHelper:
* A helper class to manage database creation and version management.
* ?????SQLiteOpenHelper?????????????????????????????????????????????
*/
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class MyOpenHelper extends SQLiteOpenHelper {
//name:??????????????
//factory???α???
//version???汾?????????????1
public MyOpenHelper(Context context?? String name?? CursorFactory factory?? int version) {
super(context?? name?? factory?? version);
// TODO Auto-generated constructor stub
}
//????????????
@Override
public void onCreate(SQLiteDatabase db) {
//???????person??
db.execSQL("create table person(_id integer primary key autoincrement?? name char(10)?? phone char(20))");
System.out.println("oncreate??????");
}
//??????????????
@Override
public void onUpgrade(SQLiteDatabase db?? int oldVersion?? int newVersion) {
// TODO Auto-generated method stub
System.out.println("onupgrade??????");
db.execSQL("alter table person add money char(20)");
}
}