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. 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. 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.
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.
Whether you are using emulator or real device, you can use DDMS ( Window-> open perspective-> DDMS ) to navigate the DB.
In DDMS, there is a File Explorer ( If not visible, window-> show view-> File Explorer ).
Now there, you can navigate to the db as /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->
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;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.