2011-05-27 34 views
0

大家好我有一个问题,即我有一些数据库表已存在于数据库中,但我无法在我的应用程序中使用它们。我能够连接到数据库,但我没有得到我已经创建的表格。我不是以编程方式创建表,但我想在我的数据库中使用现有的表。如果我编程创建表格,那么它很好,但我怎样才能使用现有的表格。 如果有人有任何想法PLZ建议我一些解决方案。如何在android中使用现有的/预定义的表格?

回答

1

对我的问题的答案是通过使用followig代码simpely复制您的数据库。

私人无效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(); 
} 
相关问题