【发布时间】:2020-10-19 05:49:59
【问题描述】:
有人知道为什么我会收到“没有”名为 COL2 的列的错误吗?
Error inserting COL2=sdfsdf
android.database.sqlite.SQLiteException: table TWhereToGoList has no column named COL2 (code 1 SQLITE_ERROR): , while compiling: INSERT INTO TWhereToGoList(COL2) VALUES (?)
我的合同类在这里创建数据库变量:
public static final class YourEntry implements BaseColumns {
public static final String TABLE_NAME = "TWhereToGoList";
public static final String intWhereToGoListOID = BaseColumns._ID;
public static final String COL2 = "COL2";
我想问你是否可以帮助我:
我的数据库助手类(sn-ps):
@Override
public void onCreate(SQLiteDatabase db) {
db.deleteDatabase(new File(DATABASE_NAME));
String createTable = ("CREATE TABLE " + Contract.YourEntry.TABLE_NAME + " (" +
Contract.YourEntry.intWhereToGoListOID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
Contract.YourEntry.COL2 + "TEXT);"
);
db.execSQL(createTable);
public boolean addData(String string) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
//Wo dass die values hingelegt werden @COL2
values.put(Contract.YourEntry.COL2, string);
我在这里得到错误:
long result = db.insert(Contract.YourEntry.TABLE_NAME, null, values);
//if date as inserted incorrectly it will return -1
if (result == -1) {
return false;
} else {
return true;
}
}
感谢您的回答,如果您有任何问题,请在下面的 cmets 中提问:)
【问题讨论】:
-
TEXT后加空格
标签: java android database sqlite