简体   繁体   English

我的android数据库在哪里?

[英]where is my android database?

i created an android application on eclipse where i made a database(just for testing) and i have to use that database in the final application to get and store information from the app. 我在eclipse上创建了一个android应用程序,在该数据库中创建了一个数据库(仅用于测试),并且必须在最终应用程序中使用该数据库来获取和存储该应用程序中的信息。 but most importantly i have to be able to share that database with others. 但最重要的是,我必须能够与他人共享该数据库。 and i cant find the file to be shared. 我找不到要共享的文件。 i dont have much knowledge of sql but i thought they were stored in .db format so i tried to search for it but couldnt find the file. 我对sql不太了解,但是我认为它们以.db格式存储,所以我尝试搜索它,但是找不到该文件。 i can see the entries but not the file. 我可以看到条目,但看不到文件。

i also ran the app on my phone and i still could not find the database file, instead i found the database files of other apps like whatsapp. 我也在手机上运行了该应用程序,但仍然找不到数据库文件,而是找到了其他应用程序(如whatsapp)的数据库文件。

so, where is my database ? 那么,我的数据库在哪里?

You can find the database you created on the internal storage of your device: 您可以在设备的内部存储器上找到创建的数据库:

/data/data/<app-package-name>/databases/<database-name>

You need to be root to see that file with a file explorer. 您需要是root用户才能使用文件浏览器查看该文件。

Whether you are using emulator or real device, you can use DDMS ( Window-> open perspective-> DDMS ) to navigate the DB. 无论使用仿真器还是真实设备,都可以使用DDMS (“ 窗口”->“打开透视图”->“ DDMS” )浏览数据库。

In DDMS, there is a File Explorer ( If not visible, window-> show view-> File Explorer ). 在DDMS中,有一个文件资源管理器 (如果看不见,则窗口->显示视图->文件资源管理器 )。

Now there, you can navigate to the db as /data/data/<app-package-name>/databases/<database-name> 现在,您可以以/data/data/<app-package-name>/databases/<database-name>导航到/data/data/<app-package-name>/databases/<database-name>

Now, to save the file, click on save button at top right corner of File Explorer. 现在,要保存文件,请单击文件资源管理器右上角的保存按钮。

Update: 更新:

Actually, before a table row insertion, I can't see the data base. 实际上,在插入表行之前,我看不到数据库。 If you want a static table with predefined data, you can do insertion at the time of table creation. 如果要使用包含预定义数据的静态表,则可以在创建表时进行插入。 Eg:- Refer onCreate() method-> 例如:-请参考onCreate()方法->

public class DbHelper extends SQLiteOpenHelper {

SQLiteDatabase db;

public DbHelper(Context context) {
    super(context, "pics.db", null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table picture(_id INTEGER PRIMARY KEY,pics varchar(20))");
    db.execSQL("insert into picture values(1001,'one.jpg')");
    db.execSQL("insert into picture values(1002,'two.jpg')");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub

}
public long insert(ContentValues cv) {
    db = getWritableDatabase();
    long l=db.insert("picture", null, cv);
    db.close();
    return l;

}
public Cursor getAllValues() {
    db=getReadableDatabase();
    Cursor cr=db.query("picture", null, null, null, null, null, "_id");
        db.close();
        return cr;
    }

}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM