Guest User

Untitled

a guest
Feb 27th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. public class DBConnect {
  2.    
  3.     private static final String DRIVER = "org.sqlite.JDBC";
  4.     private static final String DB_URL = "jdbc:sqlite:database.db";
  5.    
  6.     private static volatile Connection connection = null;
  7.  
  8.     public static Connection getConnection() {
  9.         if (connection == null) {
  10.             synchronized (DBConnect.class) {
  11.                 if (connection == null) {
  12.                     try {
  13.                 Class.forName(DRIVER);
  14.                 connection = DriverManager.getConnection(DB_URL);
  15.             } catch (ClassNotFoundException | SQLException e) {
  16.                 e.printStackTrace();
  17.                 return null;
  18.             }
  19.                 }
  20.             }
  21.         }
  22.         return connection;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment