I could use some help again, out of ideas. :( I am making JavaFX application that will use SQLite database. OpenJDK 14 with OpenJFX14 is used. In my Eclipse all is working perfectly. I tried for test to make installer with JPackage and that worked too. When I start installed application it starts ok, but for some reason refuse to connect with database.
Here is my project structure:
I have a button where when Stage is loaded I check connection. It is in file PocetnaController:
//testiranje konekcije nakon instalacije
@FXML
public void btnObracunClick(ActionEvent event) {
lblStatus.setText(model.povezanaBaza());
}
And this is code from PocetnaModel that is called:
public String povezanaBaza() {
this.konekcija = Konekcija.poveziBazu();
return (this.konekcija != null) ? "Веза са базом успостављена" : "Повезивање са базом није успело.";
}
When true it returns "Database connection established" in my language and when false "Connection with database failed".
I repeat, in Eclipse all works well. But, when start installed app I am getting "Connection with database failed". So connection returning null for some reason.
My db file is coppied by JPackage in /app folder. I tried to copy manualy Porez.db to root folder where *.exe is. Strange thing, status label doesn't change in that case. And it should, it must return true or false, don't understand that.
This is stage look when started:
Even if I rename database file in /app folder, so it can't be found my connection still returning false and update status accordingly which is ok.
Here is entire Konekcija file who has a role to take care of connection:
public static Connection poveziBazu() {
File baza = new File("Porez.db");
try {
if (baza.exists()) {
Connection con = DriverManager.getConnection("jdbc:sqlite:Porez.db");
return con;
} else {
return null;
}
} catch (Exception e) {
return null;
}
}
My first suspect is something is wrong with my created JAR, but can't be sure. Makes no sense to me to work in Eclipse and no after install.