我正在尝试设置我的
SQLite
数据库,但我收到了一些错误,我发现很难纠正。
See the error log here
这是一张被抛出的错误的图片,这是我的DatabaseHelper的代码设置。
我在日志中还收到一些其他错误,我不确定它们与什么有关--任何信息都很重要。 在这里看到logcat输出
反正错误的代码
E/SQLiteLog: (1) table my_manager has no column named
location_description in "INSERT INTO my_manager(location_name,location_county,location_description)
VALUES (?,?,?)"
2020-11-28 19:56:32.986 5665-5665/? E/SQLiteDatabase: Error inserting location_name=Blarney Stone
location_county=Cork location_description=Stone in big wall
android.database.sqlite.SQLiteException: table my_manager has no column named location_description
(code 1 SQLITE_ERROR): , while compiling: INSERT INTO
my_manager(location_name,location_county,location_description) VALUES (?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1045)
a....
这里是我的源代码。
public class MyDatabaseHelper extends SQLiteOpenHelper {
private Context context;
private static final String DATABASE_NAME = "my_manager.db";
private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME = "my_manager";
private static final String COLUMN_ID = "location_id";
private static final String COLUMN_LOCATION = "location_name";
private static final String COLUMN_COUNTY = "location_county";
private static final String COLUMN_DESCRIPTION = "location_description";
public MyDatabaseHelper(@Nullable Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context = context;
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_NAME +
" (" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_LOCATION + " TEXT, " +
COLUMN_COUNTY + " TEXT, " +
COLUMN_DESCRIPTION + " TEXT );";
db.execSQL(query);
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
void addLocation(String location, String county, String description){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(COLUMN_LOCATION, location);
cv.put(COLUMN_COUNTY, county);
cv.put(COLUMN_DESCRIPTION, description);
long result = db.insert(TABLE_NAME, null, cv);
if (result == -1){
Toast.makeText(context, "Failed!" , Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(context, "Added Successfully" , Toast.LENGTH_SHORT).show();
Cursor readAllData(){
String query = "SELECT * FROM " + TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = null;
if(db != null){
cursor = db.rawQuery(query, null);
return cursor;