0

我有下表配置

    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);
    }


}

我不确定这是否相关,但我为另一个表使用了相同的数据库名称 public static final String DBNAME = "entertainment_tracker";

我正在尝试通过创建该类的对象来使用以下查询插入一行。它在一个活动中因此使用 this 作为构造函数

DBConnectionTableMovie dbcon = new DBConnectionTableMovie(this);
String insertANewMovie = "INSERT INTO movie VALUES (NULL, 'name', '2013-05-01', 'empty')";

dbcon.open();
dbcon.addANewRow(insertANewMovie);
dbcon.close();

我收到表不存在错误。有人可以告诉我有什么问题吗?

错误日志

05-14 00:24:18.366: E/Database(856): 0x259138 上的失败 1(没有这样的表:电影)在准备“插入电影值”(NULL、“jack”、“2013-05-14”、“空的')'。

4

0 回答 0