简体   繁体   English

如何在Android设备中存储数据库?

[英]how can i store database in android device?

i have created an sqlite application that contain tables. 我创建了一个包含表的sqlite应用程序。 in that application i have retrieved data from tables. 在那个应用程序中,我已经从表中检索了数据。 the problem is how can i load that application in android device with my database. 问题是如何将数据库中的应用程序加载到android设备中。 i have tried but i didn't found answer. 我已经尝试过,但是没有找到答案。 in my application i have used the below code. 在我的应用程序中,我使用了以下代码。

try{
            String destpath = "/data/data/"+getPackageName()+"/database/mmts1.db";
            File f = new File(destpath);
            if(!f.exists())
            {
                  copyDb(getResources().getAssets().open("mmts1.db"),new FileOutputStream(destpath));
            }
        }
        catch(FileNotFoundException e)
        {
            Log.e("FileNotFoundException",e.getMessage());
        }
        catch(IOException e)
        {
            Log.e("IoException",e.getMessage());
        }

private void copyDb(InputStream open, FileOutputStream fileOutputStream) throws IOException{
            // TODO Auto-generated method stub
            byte [] buffer = new byte[1024];
            int length;
            while((length=open.read(buffer))>0)
            {
                  fileOutputStream.write(buffer,0,length);
            }
            open.close();
            fileOutputStream.close();

      }

使用SQLiteAssetHelper将数据库与您的应用程序打包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:如何将设备GPS位置存储到数据库? - Android: How to store device GPS location to database? 如何将设备连接到Android Firebase数据库 - How can I connect a device to my Android firebase database 如何在Android本地数据库上存储意图或屏幕进度? - How can I store intent or screen progress on android local database? Android - 如何将日期/时间存储到我的数据库? - Android - How can I store Date/Time to my database? 如何将对象存储到Shared-Pref或Database:Android中? - How can I store object into Shared-Pref or Database : Android? 我如何从 EditText 中获取日期,然后将其存储在 Android 的数据库中 - How can i get the date from the EditText and then store it in database in Android 如何在Android的SQLite数据库中动态存储列? - How can i store columns dynamically in SQLite database in android? 如何在 Delphi 10.3 中存储单个数据库以进行多设备访问? - How can I store a single database for multi device access in Delphi 10.3? 如何将android Studio中的sql lite数据库存储到设备内存中? - how to store sql lite database in android studio to device memory? 在Android应用程序中升级数据库时如何在设备中下载和存储图像? - How to download and store image in device while upgrading database in android application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM