如何在android中使用现有/预定义表?

时间:2011-05-27 17:53:49

标签: android sql database

大家好我有一个问题,即我有一些数据库表已经存在于数据库中,但我无法在我的应用程序中使用它们。我能够连接到数据库,但我没有得到我已经创建的表。我不是在programmectically创建表,但我想在我的数据库中使用现有的表。如果我在程序上创建表,那么它很好但我怎么能使用现有的表。 如果有人有任何想法,请告诉我一些解决方案。

1 个答案:

答案 0 :(得分:1)

回答我的问题是使用以下代码简化数据库。

private void CopyDataBase()抛出IOException {

    // open the local database 
        InputStream copy = context.getAssets().open(UR_DB_NAME);

    // path where database is created 
    String path_DB = DB_PATH + DB_NAME;

    // Open the empty dbOut as the output stream
    OutputStream dbOut = new FileOutputStream(path_DB);

    // copy database from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = copy.read(buffer)) > 0) {
        dbOut.write(buffer, 0, length);
    }

    // Close the streams
    dbOut.flush();
    dbOut.close();
    copy.close();
}