my inspection has column for comment values.but when i insert value for comment it gave logcat error for `E/SQLiteLog: (1) table inspection has no column named comment.can any one show me the error.thanks
E/SQLiteLog: (1) table inspection has no column named comment
01-25 23:20:00.999 3627-3627/? E/SQLiteDatabase: Error inserting comment=asdsd rating=4 inspection_id=0 sub_activity_id=0 activity_id=0
android.database.sqlite.SQLiteException: table inspection has no column named comment (code 1): , while compiling: INSERT INTO inspection(comment,rating,inspection_id,sub_activity_id,activity_id) VALUES (?,?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
at com.theavo.ck_app.DatabaseHelper.addInspection(DatabaseHelper.java:77)
at com.theavo.ck_app.FragmentComment.onClick(FragmentInspectionComment.java:312)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Db Helper Class
public class DatabaseHelper extends SQLiteOpenHelper {
//static variables
//version
private static final int DATABASE_VERSION = 1;
//name
private static final String DATABASE_NAME = "db1";
//table names
private static final String TABLE_INSPECTION = "inspection";
//inspection table columns name
private static final String KEY_ID = "id";
private static final String KEY_INSPECTION_ID = "inspection_id";
private static final String KEY_ACTIVITY_ID = "activity_id";
private static final String KEY_SUB_ACTIVITY_ID = "sub_activity_id";
private static final String KEY_RATING = "rating";
private static final String KEY_COMMENT = "comment";
//attachment
private static final String KEY_IMAGE = "image";
public DatabaseHelper(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_INSPECTION_TABLE = "CREATE TABLE " + TABLE_INSPECTION + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"+
KEY_INSPECTION_ID + "INTEGER,"+ KEY_ACTIVITY_ID+ "INTEGER,"+KEY_SUB_ACTIVITY_ID+"INTEGER,"+KEY_RATING+"INTEGER,"+
KEY_COMMENT+" TEXT"+ ")";
String CREATE_ATTACHMENT_TABLE = "CREATE TABLE " + TABLE_ATTACHMENT + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"+
KEY_INSPECTION_ID + "INTEGER,"+ KEY_IMAGE+ " BLOB"+")";
db.execSQL(CREATE_ATTACHMENT_TABLE);
db.execSQL(CREATE_INSPECTION_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+TABLE_ATTACHMENT);
db.execSQL("DROP TABLE IF EXISTS "+TABLE_INSPECTION);
onCreate(db);
}
//CURD
//add inspection
void addInspection(DBModelInspection inspection){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_INSPECTION_ID, inspection.getInspectionId());
contentValues.put(KEY_ACTIVITY_ID, inspection.getActivityId());
contentValues.put(KEY_SUB_ACTIVITY_ID, inspection.getSubActivityId());
contentValues.put(KEY_RATING, inspection.getRating());
contentValues.put(KEY_COMMENT, inspection.getComment());
db.insert(TABLE_INSPECTION, null, contentValues);
db.close();
}
//Add attachment
void addAttachment(DBModelAttachment attachment){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_INSPECTION_ID, attachment.getInspectionId());
contentValues.put(KEY_IMAGE, attachment.getImage());
db.insert(TABLE_ATTACHMENT, null, contentValues);
db.close();
}
public List<DBModelInspection> getAllInspection(){
List<DBModelInspection> inspectionList = new ArrayList<DBModelInspection>();
String selectQuery = "SELECT * FROM " + TABLE_INSPECTION;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
DBModelInspection inspection = new DBModelInspection();
inspection.setInspectionId(Integer.parseInt(cursor.getString(0)));
inspection.setActivityId(Integer.parseInt(cursor.getString(1)));
inspection.setSubActivityId(Integer.parseInt(cursor.getString(2)));
inspection.setRating(Integer.parseInt(cursor.getString(3)));
inspection.setComment(cursor.getString(4));
// Adding inspection to list
inspectionList.add(inspection);
} while (cursor.moveToNext());
}
// return inspection list
return inspectionList;
}
public List<DBModelAttachment> getAllAttachment(){
List<DBModelAttachment> attachmentList = new ArrayList<DBModelAttachment>();
String selectQuery = "SELECT * FROM " + TABLE_ATTACHMENT;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
DBModelAttachment attachment = new DBModelAttachment();
attachment.setInspectionId(Integer.parseInt(cursor.getString(0)));
attachment.setImage(cursor.getBlob(1));
// Adding attachment to list
attachmentList.add(attachment);
} while (cursor.moveToNext());
}
// return contact list
return attachmentList;
}
}
Aucun commentaire:
Enregistrer un commentaire