0

データベースを作成していますが、アプリケーションを実行するとデータベースが作成されず、catlog にエラーはありません。助けてください。また、fileexplorer/data/dataにはフォルダー名データベースが作成されていません。また、MySQLiteHelperで何かをコンソールクラスに出力しても、コンソールには何も出力されません。よろしくお願いします。

public class MySQLiteHelper は SQLiteOpenHelper を拡張します {

public static final String TABLE_NAME_BOY = "question_boy";
public static final String ID_BOY = "_id";
public static final String QUESTION_BOY = "questions";
public static final String ANSWER_BOY = "answer";

public static final String TABLE_NAME_GIRL = "questions_girl";
public static final String ID_GIRL = "_id";
public static final String QUESTION_GIRL = "questions";
public static final String ANSWER_GIRL = "answer";

private static final String DATABASE_NAME = "bg.database";
private static final int DATABASE_VERSION = 3;

private static final String CREATE_TABLE_BOY = "create table "
        + TABLE_NAME_BOY + "(" + ID_BOY
        + "integer primary key autoincrement, " + QUESTION_BOY + " text, "
        + ANSWER_BOY + " text);";

private static final String CREATE_TABLE_GIRL = "create table "
        + TABLE_NAME_GIRL + "(" + ID_GIRL
        + "integer primary key autoincrement, " + QUESTION_GIRL + " text, "
        + ANSWER_GIRL + " text);";

public MySQLiteHelper(Context context, String name,
        CursorFactory factory, int version) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub

    db.execSQL(CREATE_TABLE_BOY);
    db.execSQL(CREATE_TABLE_GIRL);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
    Log.w(MySQLiteHelper.class.getName(),

            "Upgrading database from version " + oldVersion + " to "

                        + newVersion + ", which will destroy all old data");

db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME_BOY);
db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME_GIRL);

onCreate(db);
}

}

4

2 に答える 2

0

デバイスがルート化されていない限り、そのファイルにアクセスすることはできません。

この質問をチェックしてください:

Android: データベース ファイルはどこに保存されますか?

于 2012-07-26T10:18:30.950 に答える
0

これにより、u のデータベースが作成されます......

public class DBHandler extends SQLiteOpenHelper {

    private SQLiteDatabase sqliteDatabaseInstance_ = null;

    public DBHandler(Context context){

        super(context, "TESTDATABASE.db", null, 1);
        sqliteDatabaseInstance_ = getWritableDatabase();
        sqliteDatabaseInstance_.execSQL("PRAGMA foreign_keys = ON;");
    }

@Override
    public void onCreate(SQLiteDatabase db) {

        try {

            db.execSQL("CREATE TABLE ACCOUNT (accountId INTEGER PRIMARY KEY, name TEXT)");

            db.execSQL("CREATE TABLE ORDER_DETAILS (orderNo INTEGER, accountId INTEGER," +
                    "FOREIGN KEY (accountId) REFERENCES ACCOUNT(accountId))");
        }catch (SQLiteConstraintException sqliteConstraintException) {

            System.out.println("sqliteConstraintException: " + sqliteConstraintException.getMessage());
        }catch (Exception e) {

            System.out.println("Exception in DBHandler.onCreate: "+e.getMessage());
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}

}

ur db ファイルは以下にある必要があります........

ファイルエクスプローラに移動 -----> データ ------> データ ------> com.test -----> TESTDATA.db

お役に立てれば。

于 2012-07-26T10:44:14.400 に答える