如何在Android中使用现有的/ predefined表?如何在、Android、predefined

2023-09-04 06:04:26 作者:输一起扛赢一起狂

大家好,我有一个问题,即我有一些数据库表的存在于数据库中。它已经有,但我不能够使用他们在我的应用程序。我能够连接到数据库,但我没有得到我刚才创建的表。我不是在创建表programmectically,但我想在我的数据库中使用现有的表。如果我programmetically创建表,然后它的罚款,但我如何使用现有的表。 如果有人有任何想法PLZ建议我一些解决方案。

Hi everyone i have one question i.e. i have some database table's which are already exist in database but i am not able to use them in my application. I am able to connect to database but i am not getting the tables which i have already created. I am not creating tables programmectically but i want to use existing table in my database. If i am creating tables programmetically then it's fine but how can i use existing table. If anyone is having any idea plz suggest me some solution.

推荐答案

回答我的问题是通过使用followig code simpelly复制数据库。

Answer to my question is simpelly copy your database by using the followig code.

私人无效CopyDataBase()抛出IOException异常{

private void CopyDataBase() throws 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();
}