无法编辑SQLite数据库名称

时间:2016-09-11 15:42:54

标签: java android sqlite android-sqlite

我无法编辑我的数据库名称,但无法找到我放入数据库的信息列表。

如果我尝试更改数据库名称" diet"除了别的什么,我仍然可以跑,但有绿色下划线拼写错误。我正在学习本教程。

public class DietDbHelper extends SQLiteOpenHelper {
    public static final String TABLE_NAME = "entry";
    public static final String COLUMN_NAME_ID = "_id";
    public static final String COLUMN_NAME_TIMESTAMP = "timestamp";
    public static final String COLUMN_NAME_WEIGHT = "weight";

    private static final String SQL_CREATE_ENTRIES =
            "CREATE TABLE " + TABLE_NAME + " (" +
                    COLUMN_NAME_ID + " INTEGER PRIMARY KEY," +
                    COLUMN_NAME_TIMESTAMP + " INTEGER," +
                    COLUMN_NAME_WEIGHT + " INTEGER )";

    private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + TABLE_NAME;

    // If you change the database schema, you must increment the database version.
    public static final int DATABASE_VERSION = 2;
    public static final String DATABASE_NAME = "diet";

    public DietDbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_ENTRIES);
    }
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // This database is only a cache for online data, so its upgrade policy is
        // to simply to discard the data and start over
        db.execSQL(SQL_DELETE_ENTRIES);
        onCreate(db);
    }
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        onUpgrade(db, oldVersion, newVersion);
    }
}

2 个答案:

答案 0 :(得分:0)

我会更改您的数据库名称代码 public static final String DATABASE_NAME =" diet&#34 ;;

要 public static final String DATABASE_NAME =" diet.db&#34 ;; 我的所有sqlite列名,表和数据库名都以绿色突出显示。

答案 1 :(得分:-1)

您必须为数据库结构中的每个更改更改数据库版本。例如改变:

public static final int DATABASE_VERSION = 2;

public static final int DATABASE_VERSION = 3;

以及每次更改等等。 我希望它会有所帮助