在SQLite中未创建数据库(找不到文件)

时间:2018-09-23 05:52:00

标签: java android sqlite

我在android studio中创建了一个名为memberInfo.db的数据库。但无法在设备文件浏览器中找到该文件。我正在使用android studio 3.1.3。我附加了设备文件浏览器的图像。

enter image description here

DBHelper.java类

public static final String DATABASE_NAME = "memberInfo.db";

public DBHelper(Context context) {
    super(context, DATABASE_NAME, null, 1);
}

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
    String SQL_CREATE_ENTRIES = "CREATE TABLE " +
            MembersMaster.Members.TABLE_NAME + " (" +
            MembersMaster.Members.COLUMN_NAME_MEMBER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
            MembersMaster.Members.COLUMN_NAME_FULLNAME + " TEXT," +
            MembersMaster.Members.COLUMN_NAME__ADDRESS + " TEXT," +
            MembersMaster.Members.COLUMN_NAME__PHONE + " TEXT," +
            MembersMaster.Members.COLUMN_NAME__EMAIL + "TEXT," +
            MembersMaster.Members.COLUMN_NAME__BIRTHDATE + "TEXT)";

            sqLiteDatabase.execSQL(SQL_CREATE_ENTRIES);

}


@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

}
}

MembersMaster.java类

package com.heisenberg.librarywiz;

import android.provider.BaseColumns;

public final class MembersMaster {

private MembersMaster() {};

public static class Members implements BaseColumns{

    public static final String TABLE_NAME = "members";
    public static final String COLUMN_NAME_MEMBER_ID = "memId";
    public static final String COLUMN_NAME_FULLNAME = "fullname";
    public static final String COLUMN_NAME__ADDRESS ="address";
    public static final String COLUMN_NAME__PHONE ="phone";
    public static final String COLUMN_NAME__EMAIL ="email";
    public static final String COLUMN_NAME__BIRTHDATE ="birthdate";

}

}

1 个答案:

答案 0 :(得分:0)

在SQL_CREATE_ENTIRES中尝试一下:

var t1 = d3
.transition() // transition "a" specifications 
...
.transition() // transition "b" specifications 
...
.transition() // transition "c" specifications 
...
.transition() // transition "d" specifications 
...
;
var t2 = d3
.transition() // transition "e" specifications 
...
.transition() // transition "f" specifications 
...
.transition() // transition "g" specifications 
...
.transition() // transition "h" specifications 
...
;
someelement1
.transition(t1).transition(t2); 
someelement2
.transition(t2).transition(t1); 

您在表达式末尾留下了分号。

另一个提示:

String SQL_CREATE_ENTRIES = "CREATE TABLE " +
        MembersMaster.Members.TABLE_NAME + " (" +
        MembersMaster.Members.COLUMN_NAME_MEMBER_ID + " INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
        MembersMaster.Members.COLUMN_NAME_FULLNAME + " TEXT, " +
        MembersMaster.Members.COLUMN_NAME__ADDRESS + " TEXT, " +
        MembersMaster.Members.COLUMN_NAME__PHONE + " TEXT, " +
        MembersMaster.Members.COLUMN_NAME__EMAIL + "TEXT, " +
        MembersMaster.Members.COLUMN_NAME__BIRTHDATE + "TEXT);";

}

对于数据库名称,请尝试仅使用小写字母,例如“ member_info.db”。 该数据库应在以下目录中创建: /data/data/your_package_name/databases/member_info.db 请让我知道它是否有效(或无效...)