Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package com.github.lbam.dcBot.Database.Factory;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class ConFactory {
  8.  
  9.     private static ConFactory connect = new ConFactory();
  10.     public static final String username = System.getenv("DBUSER");
  11.     public static final String password = System.getenv("DBPASS");
  12.     public static final String url = System.getenv("DBSERVER");
  13.  
  14.  
  15.     private ConFactory(){
  16.         try {
  17.             Class.forName("com.mysql.jdbc.Driver");
  18.         } catch (ClassNotFoundException e) {
  19.             e.printStackTrace();
  20.         }
  21.     }
  22.     private static Connection createConnection() {
  23.         Connection con = null;
  24.         try {
  25.             con = DriverManager.getConnection(username, password, url);
  26.         }catch(SQLException e){
  27.             e.printStackTrace();
  28.         }
  29.         return con;
  30.     }
  31.  
  32.     public static Connection connection(){
  33.         return connect.createConnection();
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement