当我在 android 中使用 Sqlite 数据库时
使用以下代码:
public class DBHelper extends SQLiteOpenHelper{
public String test="";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
test="here11";
// Category table create query
String CREATE_CATEGORIES_TABLE = "CREATE TABLE " + TABLE_LABELS + " ( "+ KEY_Phone + " TEXT PRIMARY KEY, " + KEY_NAME + " TEXT, " + KEY_email + " TEXT, " + KEY_Pass + " TEXT, " + KEY_MomNum + " TEXT )";
db.execSQL(CREATE_CATEGORIES_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_LABELS);
// Create tables again
onCreate(db);
}
}
我放了一个测试字符串来检查是否进入 onCreate 函数
在主课中:
DBHelper db = new DBHelper(getApplicationContext());
Toast.makeText(getApplicationContext(), db.test, Toast.LENGTH_LONG).show();
但是我显示空吐司为什么?
谢谢你。