我正在創建一個應用程序,但是當我去插入一些數據時,它不起作用。這是我的應用程序的screenshot,包括錯誤消息。這裏是我的database
職業:數據沒有被插入到SQLite數據庫中
public class database extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "STUDENT";
public static final String TABLE_NAME = "TRIP";
public static final String COL1 = "ID";
public static final String COL2 = "NAME";
public static final String COL3 = "CURRENT";
public static final String COL4 = "DESTINATION";
public static final String COL5 = "BUDGET";
public database(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table if not exists " + TABLE_NAME + "(" + COL1 + " INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,CURRENT TEXT,DESTINATION TEXT,BUDGET INTEGER)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists " + TABLE_NAME);
onCreate(db);
}
public void insertdata(String name,String current,String destination,String budget)
{
SQLiteDatabase db=this.getWritableDatabase();
db.execSQL("insert into TRIP(NAME,CURRENT,DESTINATION,BUDGET)values('" + name + "','" + current + "','" + destination + "',"+Integer.parseInt(budget)+")");
}
}
有關如何解決這個問題的任何建議?
卸載並重新安裝您的應用程序。 http://stackoverflow.com/questions/21881992/when-is-sqliteopenhelper-oncreate-onupgrade-run – laalto
如果你已經採用了Current Field Later,那麼你需要先從設備上卸載應用程序,然後再運行應用程序,ii將工作 – Vickyexpert
我想你需要在sqlite查詢結尾添加分號,比如'db.execSQL(「create table if not exists」+ TABLE_NAME +「(」+ COL1 +「INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,CURRENT TEXT,DESTINATION TEXT, BUDGET INTEGER);「);' – Pzy64