Android sql column does not exist

Robin Dijkhof

I try to create a table and insert some values but it gives an error and says there is no such kolomn. To me, it looks like I´m creating the table right. What am I doing wrong?

Edit: I changed the code t the code above, but I am still facing the same problem. I commented cv.put(colEnd, "Sales"); and the error is gone. So it seems that the problem is in creating the tabel. Any other ideas?

This is my code:

public class DatabaseHelper extends SQLiteOpenHelper{
static final String dbName="workObjectsDB";
static final String workTable="WorkObjects";
static final String colID="WorkObjectID";
static final String colStart="StartTime";
static final String colEnd="EndTime";

public DatabaseHelper(Context context) {
    super(context, dbName, null,33); 
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE "+workTable+" (" +colID+ " INTEGER PRIMARY KEY AUTOINCREMENT , " +colStart+ " TEXT, "+colEnd+ " TEXT)");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS "+workTable);
    onCreate(db);
}

public void insertSome(){
    SQLiteDatabase db=this.getWritableDatabase();
    ContentValues cv=new ContentValues();

    cv.put(colStart, "Sales");
    cv.put(colEnd, "Sales");
    db.insert(workTable, colID, cv);

    db.close();
}

public Cursor getAll(){
    SQLiteDatabase db=this.getReadableDatabase();
    Cursor cur=db.rawQuery("SELECT * from "+workTable,new String [] {});

    return cur;
}
}

Log:

11-27 16:25:14.765: E/SQLiteDatabase(7103): Error inserting EndTime=Sales StartTime=Sales 11-27 16:25:14.765: E/SQLiteDatabase(7103): android.database.sqlite.SQLiteException: table WorkObjects has no column named EndTime: , while compiling: INSERT INTO WorkObjects(EndTime,StartTime) VALUES (?,?) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:68) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:260) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:112) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1807) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1680) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at robin.urenapp.DatabaseHelper.insertSome(DatabaseHelper.java:39) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at robin.urenapp.MainActivity.onCreate(MainActivity.java:78) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.app.Activity.performCreate(Activity.java:4531) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.app.ActivityThread.access$600(ActivityThread.java:139) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.os.Handler.dispatchMessage(Handler.java:99) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.os.Looper.loop(Looper.java:154) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at android.app.ActivityThread.main(ActivityThread.java:4945) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at java.lang.reflect.Method.invokeNative(Native Method) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at java.lang.reflect.Method.invoke(Method.java:511) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 11-27 16:25:14.765: E/SQLiteDatabase(7103): at dalvik.system.NativeStart.main(Native Method)

Robin Dijkhof

Indeed it should be:

db.execSQL("CREATE TABLE "+workTable+" (" +colID+ " INTEGER PRIMARY KEY AUTOINCREMENT , " +colStart+ " TEXT, "+colEnd+ " TEXT)");

But after fixing it, I had to upgrade the database from 33 to 34.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL query column does not exist error

From Dev

PostgreSQL sql command error column 'does not exist'

From Dev

SQL: error on invalid column name that does exist

From Dev

column '_id' does not exist using SQLite with android

From Dev

Postgres column does not exist

From Dev

Column does not Exist in postgresql?

From Dev

Create SQL function referring to a table or column that does not exist (yet)

From Dev

PostgreSQL - ERROR: column does not exist SQL state: 42703

From Dev

PostgreSQL - ERROR: column does not exist SQL state: 42703

From Dev

SQL query to find where ID does not exist in another column

From Dev

Android: Table Row Insert Error. Column does not exist?

From Dev

column does not exist when it does

From Dev

Does this operator exist ? "@>" in SQL

From Dev

SQL Table does not exist

From Dev

Prevent selection of column if it does not exist

From Dev

PostgreSQL query -- column does not exist

From Dev

Pg:Error column does not exist

From Dev

PostgreSQL "Column "foo" does not exist"

From Dev

IllegalArgumentException: column '_id' does not exist?

From Dev

No such column error when column does exist

From Dev

column <column> does not exist (Django 1.8)

From Dev

Column does not exist (creating a column in a query)

From Dev

No such column error when column does exist

From Dev

Sql insert if row does not exist

From Dev

SQL Error: Tablespace does not exist

From Dev

Sql insert if row does not exist

From Dev

SQL function HASHBYTES does not exist

From Dev

Entity Framework generate sql with column that does not exist in database or code first model

From Dev

Android Databinding : package does not exist

Related Related

HotTag

Archive