![](/img/trans.png)
[英]Sqlite 'no such table' Error while Inserting Values to Database
[英]Error While Inserting in Sqlite Database Android
我被困住了。 一直在寻找可行的解决方案,但毫无头绪。
这是我的创建代码:
public class EventData extends SQLiteOpenHelper {
public static final String TABLE_COMMENTS = "EventData"; //Our Table Name(let say ) Event Data
public static final String TABLE_EVENT_NAME="eventName";
public static final String TABLE_DAY="day";
public static final String TABLE_START="sTime";
public static final String TABLE_END="eTime";
public static final String TABLE_IMGID="imgId"; //Primary Key
public static final String TABLE_SUBSCRIBE="subStatus";
//ImgId,sTime,eTime is int type(rest all are of String type)
public static final String TABLE_FILENAME="fileName";
private static final String DATABASE_NAME = "EventDB.db";
private static final int DATABASE_VERSION = 1;
// Database creation sql statement
public static final String DATABASE_CREATE = "create table "
+ TABLE_COMMENTS + "(" + TABLE_IMGID
+ " integer primary key , " + TABLE_EVENT_NAME
+ " text , " + TABLE_DAY+
" text ," + TABLE_START+
" float , " + TABLE_END+
" float , " + TABLE_SUBSCRIBE+
" integer ," + TABLE_FILENAME+
" text );";
public EventData(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(EventData.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_COMMENTS);
onCreate(db);
}
}
这是另一堂课中的“我的插入代码”:
public Comment createComment(int id,String eN,String d,int sT,int eT,String fN,Boolean sub) {
ContentValues values = new ContentValues();
// values.put(EventData.TABLE_EVENT_NAME, comment);
values.put(EventData.TABLE_IMGID, id);
values.put(EventData.TABLE_EVENT_NAME,eN);
values.put(EventData.TABLE_DAY, d);
values.put(EventData.TABLE_START, sT);
values.put(EventData.TABLE_END, eT);
int temp=0;
if(sub==true)temp=1;
values.put(EventData.TABLE_SUBSCRIBE,temp);
values.put(EventData.TABLE_FILENAME, fN);
long insertId = database.insert(EventData.TABLE_COMMENTS, null,
values);
Log.d("DB", "value inserted succcessfully");
Cursor cursor = database.query(EventData.TABLE_COMMENTS,allColumns, EventData.TABLE_IMGID + " = " + insertId, null,null, null, null);
Log.d("Sucess", "good so far");
cursor.moveToFirst();
Comment newComment = cursorToComment(cursor);
cursor.close();
return newComment;
}
这是logcat
01-30 01:31:53.141: E/Database(8787): Error inserting fileName=execute eTime=13
imgId=125 sTime=12 eventName=Execute 1.2 day=1 subStatus=0
01-30 01:31:53.141: E/Database(8787): android.database.sqlite.SQLiteException: table
EventData has no column named subStatus: , while compiling: INSERT INTO
EventData(fileName, eTime, imgId, sTime, eventName, day, subStatus) VALUES(?, ?, ?, ?,
?,?, ?);
更改数据库时,只需删除并重新安装该应用程序。 这将解决问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.