2014-02-19 65 views
-1

我遇到插入查詢問題。當我嘗試插入數據庫時​​,它在日誌貓中說active:列不存在。請你指出我在哪裏犯錯。數據庫處理程序,添加項目問題

其實我得到這個異常:

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') 

這是我SQLITEHELPER類的代碼

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 + "'" + ")"); 

    } 

,這裏是我的日誌貓

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) 

回答

2

這裏:

+ KEY_ACTIVE + "INTEGER)"; 

您必須在「INTEGER」之前插入一個空格「」;

所以:

+ KEY_ACTIVE + " INTEGER)"; 

你有這樣的問題,在你的代碼的3倍。

+2

另外,在前面的行上還有一個'',''。 – laalto

+0

這也發生了3次代碼...;) –

+0

其實這是問題「,」任何方式感謝幫助:) –

0

您錯過了列名和數據類型之間的空間。事實上,在你的所有CREATE_TABLE語句中,你都是一樣的。您需要用「INTEGER」替換「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 

希望這有助於!