Android 模拟器操作演练
2010-02-20 17:15:00 来源:WEB开发网/* ----- DataProvider.java 程式码------*/
package com.misoo.pkrr;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.util.Log;
public class DataProvider extends ContentProvider {
private static final String DATABASE_NAME = "StudNewDB";
private static final int DATABASE_VERSION = 2;
private static final String TABLE_NAME = "StudTable";
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION); }
@Override public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + "stud_no"
+ " TEXT," + "stud_name" + " TEXT" + ");");
String sql_1 = "insert into " + TABLE_NAME
+ " (stud_no, stud_name) values('S1001', 'Pam');";
String sql_2 = "insert into " + TABLE_NAME
+ " (stud_no, stud_name) values('S1002', 'Steve');";
String sql_3 = "insert into " + TABLE_NAME
+ " (stud_no, stud_name) values('S1003', 'John');";
try { db.execSQL(sql_1); db.execSQL(sql_2); db.execSQL(sql_3); }
catch (SQLException e) { Log.e("ERROR", e.toString()); }
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}
}
// ------------------------------------------------ ---------------------------------
private DatabaseHelper mOpenHelper;
@Override public boolean onCreate() {
更多精彩
赞助商链接