2012-07-26 40 views
0

我創建數據庫,但是當我運行該數據庫沒有創建應用程序並且在沒有目錄下載錯誤,請幫我不會創建SQLite數據庫。 並在fileexplorer /數據/數據有沒有創建文件夾的名稱數據庫 還當我在MySQLiteHelper打印一些東西到控制檯上的Console類沒有打印。 請提前幫助我。在我的文件瀏覽器中文摘

公共類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); 
} 

}

回答

0

這應該ü創建一個數據庫......

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

} 

烏爾數據庫文件應該是在...... ...

進入文件瀏覽器-----> data ------> data ------> com.test -----> TESTDATA.db

希望這有助於。

0

,除非你的設備是植根您不能訪問該文件。

退房這個問題:

Android: Where are database files stored?

+0

如何根設備? – 2012-07-26 10:19:55

+0

只是我想創建一個空數據庫,但如果你希望你的sqlite的文件,那麼你可以在模擬器上運行的應用程序,你的數據庫文件沒有數據文件夾 – 2012-07-26 10:20:46

+0

創建.. – 2012-07-26 10:26:06