Context:
I'm creating an application that lets a user connect to a database. This database is chosen by a FileChooser. If no database is selected, the application should connect to a sample database that comes with the program instead. The sample database is located inside src/files(/sample.db).
Problem:
The DriverManager.getConnection() method does not seem to work when I build the program as an executable JAR. It does however work in IntelliJ.
Code:
try {
System.out.println(selectedDB);
if (selectedDB == null) {
// TODO: make sure this works in JAR.
connection = DriverManager.getConnection("jdbc:sqlite::resource:files/sample.db");
} else {
connection = DriverManager.getConnection("jdbc:sqlite:" + selectedDB.toString());
}
} catch (SQLException ex) {
ex.printStackTrace();
System.out.println("If you see this message, the DatabaseManager failed to make a connection to the database.");
System.out.println("This is most likely due to a fault in the databasename");
}
Should other code extracts be needed to answer this question, please ask.
Thanks in advance!
Error:
connection remains null after the above method is done, instead of a working connection.
Pictures:
https://i.stack.imgur.com/lqGVR.jpg
(Not enough reputation to post image itsself, only recently started stackoverflowing.)
Edit: Becomes -> remains