question

Flo avatar image
Flo asked

Java, alexa & jdbc: path to sqlite database

I have reasons to store some values like URLs, Strings etc. in a sqlite database instead of using the amazon features for these kinds of tasks.

dbfile = new File("");
url = "jdbc:sqlite:" + dbfile.getAbsolutePath() + "\\src\\main\\resources\\myDb.sqlite";

Unfortunately I get the error

java.sql.SQLException: opening db: '/\src\main\resources\myDb.sqlite': Read-only file system

How can I get the correct path and get around the "read-only" error? Locally everthing works fine!

Thanks

Flo

alexajava
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Flo avatar image
Flo answered

For those who'd like to know, you can get all files from src/main/resources like so:

Path path = Paths.get(myDbHandler.class.getResource("/").toURI());
url = "jdbc:sqlite:" + path + "/" + myDb.sqlite;
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.