I have the following table configuration
package com.lynas.entertainmenttracker;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBConnectionTableMovie {
public static final String DBNAME = "entertainment_tracker";
public static final String DBTABLE = "movie";
public static final int VERSION = 1;
public static final String DBCREATE_MOVIE = "CREATE TABLE movie(" +
"movie_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"movie_name VARCHAR, " +
"movie_release_date date, " +
"movie_extra VARCHAR)";
private final Context context;
private DBHelper dbh;
private SQLiteDatabase db;
public DBConnectionTableMovie(Context ctx){
this.context = ctx;
dbh = new DBHelper(context);
}
private static class DBHelper extends SQLiteOpenHelper{
DBHelper(Context context){
super(context, DBNAME,null,VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
//try{
db.execSQL(DBCREATE_MOVIE);
//}catch(SQLException e){
//e.printStackTrace();
//}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE movie IF EXISTS");
onCreate(db);
}
}
public DBConnectionTableMovie open() throws SQLException{
db = dbh.getWritableDatabase();
return this;
}
public void close() throws SQLException{
dbh.close();
}
public void addANewRow(String inserQuery){
db.execSQL(inserQuery);
}
public void updateRow(String updateQuery){
db.execSQL(updateQuery);
}
public void deleteRow(String deleteQuery){
db.execSQL(deleteQuery);
}
public Cursor selectRow(String selectQuery){
return db.rawQuery(selectQuery, null);
}
}
I am not sure if this is relevant or not but i used same database name for another table public static final String DBNAME = "entertainment_tracker";
I am trying to insert a row using following query by creating an object of that class. its in an activity thus used the this as constructor
DBConnectionTableMovie dbcon = new DBConnectionTableMovie(this);
String insertANewMovie = "INSERT INTO movie VALUES (NULL, 'name', '2013-05-01', 'empty')";
dbcon.open();
dbcon.addANewRow(insertANewMovie);
dbcon.close();
I am getting table not exist error. Can someone tell me whats wrong?
error log
05-14 00:24:18.366: E/Database(856): Failure 1 (no such table: movie) on 0x259138 when preparing 'INSERT INTO movie VALUES (NULL, 'jack', '2013-05-14', 'empty')'.