[英]android.database.sqlite.SQLiteException: no such table
[英]android.database.sqlite.SQLiteException: no such table: tblUserResponse
我是SqlLite數據庫的新手。 我已經使用SqlLite Database Browser
創建了數據庫,並將其保存在路徑為src/com/example/hello/databases/
Android App Project文件夾中
我已經創建了表格。 現在,當我嘗試運行代碼時,它顯示錯誤,找不到這樣的表。
我的代碼如下:
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 3;
private static final String DATABASE_NAME = "db_admin";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
// Adding User Response When He/She attempts Questions...
void addUserResponse(UserResponse response) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("QId", response.getQId());
values.put("OptionId", response.getOptionId());
values.put("Responsedate", response.getResponseDate());
// Inserting Row
db.insert("tblUserResponse", null, values);
db.close();
}
}
插入值為:
DatabaseHandler db = new DatabaseHandler(this);
db.addUserResponse(new UserResponse("1", "1", "hello"));
db.addUserResponse(new UserResponse("2", "1", "hello"));
db.addUserResponse(new UserResponse("3", "3", "hello"));
db.addUserResponse(new UserResponse("4", "2", "hello"));
數據庫存儲在/data/data/your.app.name/databases/中。 因此,可能嘗試運行代碼,以將外部創建的數據庫保留在此位置。 但我認為,如果您不扎根,則無法訪問此位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.