慕运维8079593
下面是一个如何创建和填充数据库的例子,您可以在应用程序安装上这样做,这只会创建一个条目,尽管这样做可能对您想要做的事情效率很低。private static class settingsDatabaseHelper extends SQLiteOpenHelper{
//SQL String for creating the table required
private static final String CREATE_SETTINGS_TABLE = "CREATE TABLE tbl_settings(" +
"_ID INTEGER PRIMARY KEY AUTOINCREMENT," +
"VOIPUSERNAME TEXT," +
"VOIPAUTHID TEXT," +
"PASSWORD TEXT," +
"VOIPDISPLAYNAME TEXT," +
"SIPPROXYSERVER TEXT," +
"SIPREGISTRAR TEXT," +
"SIPREALM TEXT," +
"EXPIRESTIME INTEGER);";
//constructor
public settingsDatabaseHelper(Context context, String name,
CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_SETTINGS_TABLE);
ContentValues initialValues = new ContentValues();
initialValues.put("VOIPUSERNAME", "xxxxx");
initialValues.put("VOIPAUTHID", "xxxxxxxxxx");
initialValues.put("PASSWORD", "xxxxxx");
initialValues.put("VOIPDISPLAYNAME", "xxxxxxxxx");
initialValues.put("SIPPROXYSERVER", "xxxxxxxxxxxxx");
initialValues.put("SIPREGISTRAR", "xxxxxxxxxxx");
initialValues.put("SIPREALM", "xxxxxxxxxx");
initialValues.put("EXPIRESTIME", xxxxxxxxxxx);
Log.d("1.6", "gets to here");
db.insert(SETTINGS_TABLE, null, initialValues);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to " +
newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + SETTINGS_TABLE);
onCreate(db);
} }//end helper class}