-1

I am having trouble with insert query. when i try to insert into the database, it says in the log cat that active: column does not exists. can you please point out where am i making mistake.

I am actually getting this exception:

SQLiteException: table video has no column named active: , while compiling: insert into video (fav, path, subcat_id , video_name, active) VALUES ('0','/mnt/sdcard/Samsung','videocat','Samsung','1')

this is the code of my SQLITEHELPER class

public class DatabaseHelper extends SQLiteOpenHelper {

    //changing master
    // Logcat tag
    //add comment
    private static final String LOG = "DatabaseHelper";

    // Database Version
    private static final int DATABASE_VERSION = 9;

    // Database Name

    private static final String DATABASE_NAME = "contactsManager";

    // Table Names

    private static final String TABLE_VIDEO = "video";
    private static final String TABLE_PICTURE = "picture";
    private static final String TABLE_MUSIC = "music";

    // Common column names

    private static final String KEY_ID = "id";
    private static final String KEY_FAV = "fav";
    private static final String KEY_ACTIVE = "active";

    // MUSIC Table - column names

    private static final String KEY_MUSIC_PATH = "path";
    private static final String KEY_MUSIC_ALBUM = "is_album";
    private static final String KEY_MUSIC_NAME = "music_name";



    // PICTURE Table - column names

    private static final String KEY_PICTURE_PATH = "path";
    private static final String KEY_PICTURE_ALBUM = "is_album";
    private static final String KEY_PICTURE_NAME = "picture_name";

    // VIDEO Table - column names

    private static final String KEY_VIDEO_PATH = "path";
    private static final String KEY_VIDEO_SUBCAT_ID = "subcat_id";
    private static final String KEY_VIDEO_NAME = "video_name";


    // Table Create Statements


    // Video table create statement
    private static final String CREATE_TABLE_VIDEO = "CREATE TABLE "
            + TABLE_VIDEO + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + KEY_FAV + " INTEGER," 
            + KEY_VIDEO_PATH + " TEXT," 
            + KEY_VIDEO_SUBCAT_ID + " TEXT," 
            + KEY_VIDEO_NAME + " TEXT"
            + KEY_ACTIVE + "INTEGER)";

    // PICTURE table create statement
    private static final String CREATE_TABLE_PICTURE = "CREATE TABLE "
            + TABLE_PICTURE + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + KEY_FAV + " INTEGER,"
            + KEY_PICTURE_PATH + " TEXT," 
            + KEY_PICTURE_ALBUM+ " INTEGER,"
            + KEY_PICTURE_NAME + " TEXT" 
            + KEY_ACTIVE + "INTEGER)";

    // MUSIC table create statement
    private static final String CREATE_TABLE_MUSIC = "CREATE TABLE "
            + TABLE_MUSIC + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + KEY_FAV + " INTEGER,"
            + KEY_MUSIC_PATH + " TEXT," 
            + KEY_MUSIC_ALBUM+ " INTEGER,"
            + KEY_MUSIC_NAME + " TEXT"
            + KEY_ACTIVE + "INTEGER)";

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }



    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        // creating required tables

        db.execSQL(CREATE_TABLE_PICTURE);
        db.execSQL(CREATE_TABLE_MUSIC);
        db.execSQL(CREATE_TABLE_VIDEO);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        // on upgrade drop older tables

        db.execSQL("DROP TABLE IF EXISTS " + TABLE_VIDEO);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_PICTURE);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_MUSIC);

        // create new tables
        onCreate(db);
    }




    // add videos
    public void addvideos(Video item, int active, String subcat) {
        SQLiteDatabase db = this.getWritableDatabase();


        db.execSQL("insert into video (fav, path, subcat_id , video_name, active) VALUES (" + "'" + item.getFavourite() + "',"+ "'" + item.getPath() +  "'," + "'" + subcat + "'," + "'" + item.getName() +"'," + "'" + active + "'" + ")");

    }

    // add pictures
    public void addpictures(Picture item, int is_album, int active) {
        SQLiteDatabase db = this.getWritableDatabase();


        db.execSQL("insert into picture (fav, path, is_album , picture_name, active) VALUES (" + "'" + item.getFavourite() + "',"+ "'" + item.getPath() + "'," + "'"  + is_album + "'," + "'" + item.getName() +"'," + "'" + active + "'" + ")");

    }

    // add music
    public void addmusic(Music item, int catid, int active) {
        SQLiteDatabase db = this.getWritableDatabase();


        db.execSQL("insert into music (fav, path, cat_id , video_name, active) VALUES (" + "'" + item.getFavourite() + "',"+ "'" + item.getPath() + "'," + "'"  + catid + "'," + "'" + item.getName() +"'," + "'" + active + "'" + ")");

    }

and here is my Log Cat

02-19 17:21:46.842: E/AndroidRuntime(15469): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tvdashboard.database/com.tvdashboard.main.VideoSection}: android.database.sqlite.SQLiteException: table video has no column named active: , while compiling: insert into video (fav, path, subcat_id , video_name, active) VALUES ('0','/mnt/sdcard/Samsung','videocat','Samsung','1')
02-19 17:21:46.842: E/AndroidRuntime(15469):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at android.app.ActivityThread.access$600(ActivityThread.java:128)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at android.os.Looper.loop(Looper.java:137)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at android.app.ActivityThread.main(ActivityThread.java:4514)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at java.lang.reflect.Method.invokeNative(Native Method)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at java.lang.reflect.Method.invoke(Method.java:511)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at dalvik.system.NativeStart.main(Native Method)
02-19 17:21:46.842: E/AndroidRuntime(15469): Caused by: android.database.sqlite.SQLiteException: table video has no column named active: , while compiling: insert into video (fav, path, subcat_id , video_name, active) VALUES ('0','/mnt/sdcard/Samsung','videocat','Samsung','1')
02-19 17:21:46.842: E/AndroidRuntime(15469):    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
02-19 17:21:46.842: E/AndroidRuntime(15469):    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
Hassaan Rabbani
  • 2,469
  • 5
  • 30
  • 55

2 Answers2

2

Here:

+ KEY_ACTIVE + "INTEGER)";

You must insert a SPACE before "INTEGER)";

So:

+ KEY_ACTIVE + " INTEGER)";

You have this issue 3 times in your code.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
0

You're missing a space between the column name and the data type. In fact, in all of your CREATE_TABLE statements, you have the same. You'll need to replace "INTEGER)" with " INTEGER)"

private static final String CREATE_TABLE_VIDEO = "CREATE TABLE "
        + TABLE_VIDEO + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
        + KEY_FAV + " INTEGER," 
        + KEY_VIDEO_PATH + " TEXT," 
        + KEY_VIDEO_SUBCAT_ID + " TEXT," 
        + KEY_VIDEO_NAME + " TEXT"
        + KEY_ACTIVE + " INTEGER)"; // SPACE INSERTED BEFORE INTEGER

Hope this helps!

laminatefish
  • 5,197
  • 5
  • 38
  • 70