2

I would like to access a database file from my project. I have created an assets folder in my project and added the file to the folder.

How do I get the url of the database so that I can use it with the jetbrains form like this:

Database.connect("jdbc:h2:file:~$path/testDB", driver = "org.h2.Driver")

Here is the Screenshot of the file:

enter image description here

Jawad Malik
  • 608
  • 5
  • 21
Dinu Nicolae
  • 1,019
  • 2
  • 17
  • 42
  • 1
    There is no URL to that database. You will need to copy it to a file on the filesystem (e.g., in `getFilesDir()`) and then use that. Also note that using JDBC on Android is very unusual. – CommonsWare Apr 06 '19 at 18:26
  • It might be unusual, but I can not change the database, unless I copy it into another database type. – Dinu Nicolae Apr 06 '19 at 19:05
  • "unless I copy it into another database type" -- the native database for Android is SQLite. You can convert your database to SQLite and package that with your app. You will find **much** better support for SQLite on Android than you will find for JDBC. – CommonsWare Apr 06 '19 at 19:06
  • you can also use room database library for this. https://stackoverflow.com/questions/44263891/how-to-use-room-persistence-library-with-pre-populated-database . Might be little advanced if you are a beginer. – Vihaan Verma Apr 06 '19 at 19:07
  • but how do I copy it to the filesystem. I come form the iOS world, so sorry if I ask stupid questions. – Dinu Nicolae Apr 06 '19 at 19:07

0 Answers0