我有下面的代碼,其收集從在佈局字段中的數據(同一類)並嘗試把它放在msqlite數據庫內:錯誤時插入到MSQLite
public void submitOrder(Order order_) {
SQLiteDatabase db=DBHelper.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(DatabaseHelper.colName, order_.name);
cv.put(DatabaseHelper.colLink, order_.link);
cv.put(DatabaseHelper.colPrice, order_.price);
cv.put(DatabaseHelper.colDateYear, order_.year);
cv.put(DatabaseHelper.colDateMonth, order_.month);
cv.put(DatabaseHelper.colDateDay, order_.day);
db.insert(DatabaseHelper.orderTable, null, cv);
db.close();
和我有MSQlite數據庫幫助類我已經創建了:
package com.Sagi.MyOrders;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DatabaseHelper extends SQLiteOpenHelper {
static final String dbName="DBname";
static final String orderTable="Orders";
static final String colName="OrderName";
static final String colLink="OrderLink";
static final String colDateYear="DateYear";
static final String colDateMonth="DateMonth";
static final String colDateDay="DateDay";
static final String colPrice="OrderPrice";
static String CREATE_T;
public DatabaseHelper(Context context) {
super(context, dbName, null,1);
}
/** Called when the activity is first created. */
@Override
public void onCreate(SQLiteDatabase db) {
CREATE_T="CREATE TABLE orderTable ("
+ "colName TEXT,"
+ "colLink TEXT,"
+ "colPrice TEXT,"
+ "colDateYear INTEGER,"
+ "colDateMonth INTEGER,"
+ "colDateDay INTEGER);";
db.execSQL(CREATE_T);
Log.e("Table creator","Table Created successfully");
}
當我運行它,然後點擊按鈕存儲在數據庫中的信息,我得到一個錯誤信息:
06-02 06:19:43.454: E/Database(1570): android.database.sqlite.SQLiteException: table Orders has no column named OrderPrice: , while compiling: INSERT INTO Orders(DateDay, DateMonth, OrderLink, OrderName, OrderPrice, DateYear) VALUES(?, ?, ?, ?, ?, ?);
和I級消息:
06-02 06:19:43.444: I/Database(1570): sqlite returned: error code = 1, msg = table Orders has no column named OrderPrice
希望你能幫助...謝謝!
清除數據或者反安裝應用程序,然後它會工作 –