I'm making a Java app that uses an SQLite database to store product information. To get the info I made a class with static methods, and a static variable private static Connection c
so that it stays active until the program ends.
public static void Init() {
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:test.db");
crearTablas();
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
}
Multiple queries are performed. Should I close the database connection at the end of each query, or keep it active and reuse (to close when I stop using the program with a static method)?
The app is for a Windows system (stock control for a computer store), not for phone.