如何在Android中使用现有的/ predefined表? [英] How to use existing/Predefined table in android?

查看:132
本文介绍了如何在Android中使用现有的/ predefined表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个问题,即我有一些数据库表的存在于数据库中。它已经有,但我不能够使用他们在我的应用程序。我能够连接到数据库,但我没有得到我刚才创建的表。我不是在创建表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();
}

这篇关于如何在Android中使用现有的/ predefined表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆