2

In Android Studio. I have been on and off programming for a few years. Trying to get back into it once again. I wrote the code below to connect, query and then update the sqlite database in a while loop. However, I am doing something wrong because I am getting a read-only file system error. I have put in bogus db strings and I get the same error.

I have been trying to figure out the solution for over 2 weeks now and the keyboard is about to fly across the room. Any ideas are appreciated!


String url = "jdbc:sqlite:currentDBPath";
 
SQLiteConfig config = new SQLiteConfig();

config.setOpenMode(SQLiteOpenMode.READWRITE);

java.sql.Connection con = DriverManager.getConnection(url, config.toProperties());

Statement stmt = con.createStatement(
         ResultSet.TYPE_SCROLL_INSENSITIVE,
         ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = stmt.executeQuery("Select id from round_table");

java.sql.SQLException: opening db: 'currentDBPath': Read-only file system
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
Gunner
  • 21
  • 1
  • OK ... so I assume that you are trying to implement an Android app here. Correct? And that you are trying to create / use an SQLite database on the user's device? In that case, you are going to need to use a path for a writeable file system. So where do you actually want to write to? Internal storage? External storage? (See https://stackoverflow.com/questions/5092591) If the latter, your app needs to be granted permission to write to external storage. – Stephen C Jan 04 '22 at 02:11
  • Note that Android provides its own on-device database called [Room](https://developer.android.com/jetpack/androidx/releases/room). That may be a better option than SQLite + JDBC + a SQLite for Android driver. – Stephen C Jan 04 '22 at 02:13
  • Yes. Sorry. It is an android app. I use ROOM throughout my app, but I needed to be run a secondary thread performing multiple while loop updates. This is all happening in the background and it's the most critical piece to my app. This was the first loop. I thought this was the best approach. – Gunner Jan 04 '22 at 02:43
  • What about the internal / external storage question? – Stephen C Jan 04 '22 at 02:45
  • It's internal for now. – Gunner Jan 04 '22 at 02:51
  • Maybe see this Answer to [Does Android Support JDBC](https://stackoverflow.com/questions/1728476/does-android-support-jdbc/62730411#62730411) and/or [How to use openDatabase method in android.database.sqlite.SQLiteDatabase](https://www.tabnine.com/code/java/methods/android.database.sqlite.SQLiteDatabase/openDatabase) – Scratte Jan 04 '22 at 12:34
  • Thanks. I will look into those potential fixes. My concern is that it seems like i am mixing even more connection types together to make it work. The odd item that i also ran into is when i hard coded the database i got the same error. It didn't matter what the file was or even if the file existed or not. Got the same error..... – Gunner Jan 04 '22 at 13:47

0 Answers0