0

It was working fine, but after I rebooted the server, tomcat started to give me this error every time the JSP tries to insert something into the SQLite database in question. However, any kind of read operation works fine.

javax.servlet.ServletException: org.sqlite.SQLiteException:
[SQLITE_READONLY]  Attempt to write a readonly database (attempt to write a readonly database)

The database file was located at /var/lib/tomcat9/dbs/something.db and the following is permission, user:group for those directory and file.

  • /var/lib/tomcat9/dbs: 775 tomcat:tomcat
  • something.db: 644 tomcat:tomcat

Before the reboot, I had no problem with this setup, but after the reboot, I always get an error. I tried the following and nothing fixed the issue.

  • change the permission to 777 for both /var/lib/tomcat9/dbs and something.db
  • add the following lines to the java connector class before it tries to make a connection
SQLiteConfig config = new SQLiteConfig();
config.setReadOnly(false);

Any ideas on why and how to fix this issue?

So far the only working solution I found was moving the file to <NAME_OF_MY_APP>/src/main/webapp/WEB-INF/sql/something.db so that the db file could be ended up on /var/lib/tomcat9/webapps/<NAME_OF_MY_APP>/WEB-INF/sql after the war file deployment and the change the resource url on context.xml accordingly. Is this something okay to do? If not, what's the alternative?

e1630m
  • 11
  • 3
  • Does this answer your question? [How to allow Tomcat war app to write in folder](https://stackoverflow.com/questions/56827735/how-to-allow-tomcat-war-app-to-write-in-folder) – Olaf Kock May 24 '22 at 13:22
  • @OlafKock Thanks. I haven't actually tried it yet, since I just moved them to WEB-INF directory, but I think that might work. However, mystery still remains since I was able to write on `/var/lib/tomcat9/dbs/something.db` before the reboot, but not after the reboot (even with the 777 permission). – e1630m Jun 01 '22 at 01:41

0 Answers0