lundi 6 juillet 2015

Reusing SQLite Connection or connect every time?

first of all, sorry for my english, i'm using google translate. I'm making a java app that use SQLite database to store products information. For get the info, i made a class with static methods, and a static variable "private static Connection c" 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");
}

while the program is used, multiple queries are performed. Should I close the variable at the end of each query? or keep it active and reusing it and close when you stop using the program with a static method?

Thanks!

Aucun commentaire:

Enregistrer un commentaire