I have the following code which collects data (same class) from fields in the layout and tries to put it inside a msqlite database :
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();
And i have the MSQlite database helper Class i’ve created :
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");
}
When i run it and click on the button to store the info in the DB, i get an error message :
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(?, ?, ?, ?, ?, ?);
And an I level message :
06-02 06:19:43.444: I/Database(1570): sqlite returned: error code = 1, msg = table Orders has no column named OrderPrice
Hope you can help … thanks !
It says
table Orders has no column named OrderPrice. The reason is you don’t update your database. Simply Uninstall/ReInstall your app. And everything will be ok.After your edit:
You create your table with
Which means you create a table called
orderTable.But in your insert:
You use
DatabaseHelper.orderTablewhich isstatic final String orderTable="Orders";
They are not equal so you are getting this error.Change your orderTable variable or the table name, then you will be ok
Hope this helps