Answer the question
In order to leave comments, you need to log in
Where should the sqlite database file be located in the program folder so that the program can see it?
I wrote a program for a friend in JavaFX. Intelij Idea development environment. The database is SQlite.
What I want to achieve:
- to have a folder with the program, which will contain a database file (database.db)
- the necessary libraries for the program to work
- an executable program file, since the user is used to that all programs are launched through this file
I made a build program . Many files appeared in the output folder after that. Of all of them, I copied the ones I needed to a separate folder on my desktop so that I could wrap the jar file into an exe and then make an installer out of it all (to make it easier to install the program on other computers)
After I made the installer of the program, the program starts and works fine, but the database in the program and the database that is in the database.db file do not match. It seems that the database file was sewn into a jar file during the build. And all the information in the program is taken not from a file in the program folder, but from a file that is in the jar file. I don’t need this, I need to have a database.db file in the program folder that can be edited (for example, with the DB Browser browser) and that all information after that changes in the program too.
In order to make an exe file, I used Launch4j, and to create an installer - Inno Setup
Where should I put the database.db file so that the program takes information from it?
This is the class in which I wrote the path to the database file:
public class DbConnection {
private static final String SQCONN = "jdbc:sqlite::resource:database.db";
public static Connection getConnection() throws SQLException{
String path = SQCONN;
try {
Class.forName("org.sqlite.JDBC");
return DriverManager.getConnection(path);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return null;
}
}
Answer the question
In order to leave comments, you need to log in
looked at myself - windows machine
without spring it is possible in my opinion
String.format("%s/src/main/resources/%s",
System.getProperty("user.dir"), resourceFileName);
jdbc:sqlite:database.db is not a sqlite file
If you want to shove it into the root directory, then here
Or in any folder, even on a network"jdbc:sqlite:z:\\database.sqlite"
Hello!
The database file will be where you specify the path to create it. It would be logical if you install the program, then get this path and unpack or create a database there.
It looks like you have a javafx project. In intellij idea there is an option to create an exe artifact.
If this is a pure database, then there is no point in packing it into a jar. You can create a database at the first start of the program and that's it. And already at subsequent launches (since the database is available), it will read the data
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question