gpt4 book ai didi

java - E/SQLite日志: (1) table Estudiantes has no column named calificacion in android

转载 作者:太空宇宙 更新时间:2023-11-04 09:04:19 26 4
gpt4 key购买 nike

这是我正在使用的类

public class DBHelper extends SQLiteOpenHelper {

private static final String DB_FILE = "Database.db";
private static final String TABLE = "Estudiantes";
private static final String FIELD_ID = "id";
private static final String FIELD_NAME = "nombre";
private static final String FIELD_GRADE = "calificacion";

public DBHelper(Context context){
super(context, DB_FILE, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE + "(" +
FIELD_ID + " INTEGER PRIMARY KEY, " +
FIELD_NAME + " TEXT, " +
FIELD_GRADE + " INTEGER);";
db.execSQL(query);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String query = "DROP TABLE IF EXISTS ?";
String[] params = {TABLE};
db.execSQL(query, params);
}

public void save(String nombre, int calificacion){
SQLiteDatabase db = getWritableDatabase();
ContentValues valores = new ContentValues();

valores.put(FIELD_NAME, nombre);
valores.put(FIELD_GRADE, calificacion);

db.insert(TABLE, null, valores);
}

public int delete(String nombre){
SQLiteDatabase db = getWritableDatabase();
String clause = FIELD_NAME + " = ?";
String[] args = {nombre};
return db.delete(TABLE, clause, args);
}

public int find(String nombre){
SQLiteDatabase db = getReadableDatabase();
String filtrito = FIELD_NAME + " = ?";
String[] args = {nombre};

Cursor c = db.query(TABLE, null, filtrito, args, null, null, null);
int result = -1;

if(c.moveToFirst()) {
result = c.getInt(2);
}

return result;
}
}

这是我收到的错误消息:

E/SQLiteLog: (1) table Estudiantes has no column named calificacion
E/SQLiteDatabase: Error inserting calificacion=80 nombre=Fer
android.database.sqlite.SQLiteException:
table Estudiantes has no column named calificacion (code 1): , while compiling:
INSERT INTO Estudiantes(calificacion,nombre) VALUES (?,?)

最佳答案

看起来您稍后在数据库中添加了 calificacion 列。我会执行以下操作之一:

  1. 卸载并重新安装您的应用。
  2. 最好、更好的方法是在 onUpdate 方法中删除重新创建Estudiantes表,并在每次更改架构时增加db版本。

关于java - E/SQLite日志: (1) table Estudiantes has no column named calificacion in android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60422419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com