I am using RoomDB in my sample app.i am able to perform CRUD operation on DB. but i am not able to view db file.i want to view table structure in sqlite DB browser.
this is my APPDatabase class
@Database(entities = {User.class}, version = 1,exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
private static AppDatabase INSTANCE;
public abstract UserDao userDao();
public static AppDatabase getAppDatabase(Context context) {
if (INSTANCE == null) {
INSTANCE =
Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "user-database")
.allowMainThreadQueries()
.build();
}
return INSTANCE;
}
public static void destroyInstance() {
INSTANCE = null;
}
}
help me to get DB file.
To open the database in DB Browser do the following; Click on the 'open database' button in the toolbar. Navigate to where you have stored the database file on your local machine, select it and click open.
Go To App Inspection . Then select the process. Database Inspector will now show the database contents. in 2021, with current Android Studio, this should be the only accepted answer.
Room vs SQLiteRoom provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite. In the case of SQLite, There is no compile-time verification of raw SQLite queries. But in Room, there is SQL validation at compile time.
This is how I have done it. In Android Studio 3.1,
<your package>
/databasesIf you can't see your database file, consider to copy the file with following code
fun exportDB(context: Context){
try {
val sd = Environment.getExternalStorageDirectory()
if (sd.canWrite()) {
val backupDBPath = "database.db"
val currentDB = context.getDatabasePath("database.db")
val backupDB = File(sd, backupDBPath)
val src = FileInputStream(currentDB).getChannel()
val dst = FileOutputStream(backupDB).getChannel()
dst.transferFrom(src, 0, src.size())
src.close()
dst.close()
Log.i("database","export database done. Original path: $currentDB")
}else{
Log.i("database","cannot write database")
}
} catch (e: Exception) {
Log.e("database","export database failed. "+e.message)
}
}
UPDATE: the db file is empty, and u need .db-shm and .db-wal to open .db file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With