我有以下代码从布局中的字段收集数据(同一类)并尝试将其放入 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
希望你能帮助...谢谢!