0
....私は私のDBを作成し、いくつかの項目を挿入AndroidのSQLiteは()メソッドのonCreateを使用して、最初のロードでContentValuesを挿入した後、空になったコードはまだ完了していないので、私はアンドロイドの開発に新しいです
内部はonCreate()
の方法でcontentValues
を使用していますが、アプリケーションの実行後にDBを読み込もうとしましたが、空でした。 アプリを起動して初めてonCreate()
メソッドを使用しますが、残念ながら挿入しません。ここに私のコードです
...ここ
package com.example.axel.spotopia;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.security.PublicKey;
public class SpotopiaDBHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "spotopia";
private static final int DB_VESION = 1;
public SpotopiaDBHelper(Context context) {
super(context, DB_NAME, null, DB_VESION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
updateMyDB(db, 0, DB_VESION);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
updateMyDB(db, oldVersion, newVersion);
}
private void insertSpot(SQLiteDatabase db, String name, String address, String note, String rank) {
ContentValues content = new ContentValues();
content.put("NAME", name);
content.put("ADDRESS", address);
content.put("NOTE", note);
content.put("RANK", rank);
db.insert(DB_NAME, null, content);
}
private void updateMyDB(SQLiteDatabase db, int oldVersion, int newVersion)
{
if (oldVersion < 1) {
db.execSQL("CREATE TABLE SPOT ("
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "NAME TEXT, "
+ "ADDRESS TEXT, "
+ "NOTE TEXT, "
+ "RANK REAL);");
insertSpot(db, "jaz", null, null, "8");
insertSpot(db, "jaz1", null, null, "9");
insertSpot(db, "jaz2", null, null, "10");
}
}
}