0
我想的SQLite添加到我的項目,但我有這樣的錯誤,當我將數據發送到數據庫錯誤使用SQLite在Android
> 03-21 18:59:20.742 27050-27050/org.lili14.taps E/SQLiteLog: (1) table > Images_table has no column named TAG0 03-21 18:59:20.782 > 27050-27050/org.lili14.taps E/SQLiteDatabase: Error inserting ... > android.database.sqlite.SQLiteException: table Images_table has no > column named TAG0 (code 1): , while compiling: INSERT INTO > Images_table(TAG0,URL) VALUES (?,?) > at > android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native > Method) > at > android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:917) > at > android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:528) > at > android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) > at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) > at > android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) > at > android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1547) > at > android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1404) > at > org.lili14.taps.database.DatabaseHelper.insertData(DatabaseHelper.java:48) > at org.lili14.taps.TwoFragment$1.onClick(TwoFragment.java:75) > at android.view.View.performClick(View.java:4785) > at android.view.View$PerformClick.run(View.java:19869) > at android.os.Handler.handleCallback(Handler.java:739) > at android.os.Handler.dispatchMessage(Handler.java:95) > at android.os.Looper.loop(Looper.java:155) > at android.app.ActivityThread.main(ActivityThread.java:5696) > at java.lang.reflect.Method.invoke(Native Method) > at java.lang.reflect.Method.invoke(Method.java:372) > at > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029) > at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
這是我DatabaseHelper類
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "Images.db";
public static final String TABLE_NAME = "Images_table";
public static final String col01 = "URL";
public static final String col02 = "TAG0";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_NAME + " (id INTEGER PRIMARY KEY AUTOINCREMENT, TAG0 TEXT, URL TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+ TABLE_NAME);
onCreate(db);
}
public boolean insertData(String url, String tag){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(col01, url);
contentValues.put(col02, tag);
long result = db.insert(TABLE_NAME, null, contentValues);
if(result == -1){
return false;
}
else{
return true;
}
}
public Cursor getAllDate(){
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("Select * from "+TABLE_NAME, null);
return res;
}
}
如果我刪除ContentValue工作第二值,但沒有保存所有數據 我要救僅有2值和自動生成的ID在構造
它的工作的人謝謝 – Heisenberg06