Last active
December 14, 2015 06:09
-
-
Save guenodz/5040411 to your computer and use it in GitHub Desktop.
A Java class for SQLite conection Helper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
public class ConnectionManager { | |
private static Connection connection; | |
// path to the database file | |
private static final String dbPath = "tips.db"; | |
private ConnectionManager() { | |
try { | |
Class.forName("org.sqlite.JDBC"); | |
connection = DriverManager.getConnection("jdbc:sqlite:" + dbPath); | |
} catch (ClassNotFoundException e) { | |
e.printStackTrace(); | |
} catch (SQLException e) { | |
e.printStackTrace(); | |
} | |
} | |
public static Connection getInstance() { | |
if (connection == null) | |
new ConnectionManager(); | |
return connection; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment