Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DBConnect {
- private static final String DRIVER = "org.sqlite.JDBC";
- private static final String DB_URL = "jdbc:sqlite:database.db";
- private static volatile Connection connection = null;
- public static Connection getConnection() {
- if (connection == null) {
- synchronized (DBConnect.class) {
- if (connection == null) {
- try {
- Class.forName(DRIVER);
- connection = DriverManager.getConnection(DB_URL);
- } catch (ClassNotFoundException | SQLException e) {
- e.printStackTrace();
- return null;
- }
- }
- }
- }
- return connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment