Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. import java.sql.Connection;
  2.  
  3. public class MyConnection {
  4.     private static Connection conn;
  5.  
  6.     public static Connection getConnection(){
  7.         if(conn == null){
  8.             openConnection();
  9.         }
  10.         return conn;
  11.     }
  12.  
  13.     private static void openConnection(){
  14.         //put in your conn open code here
  15.     try {
  16.             Class.forName("com.mysql.jdbc.Driver");    
  17.             url="jdbc:mysql://192.168.20.98:3306/games";
  18.             this.con=DriverManager.getConnection(url,"user","pass");
  19.         } catch (SQLException ex) {
  20.             Logger.getLogger(DBManager.class.getName()).log(Level.SEVERE, null, ex);
  21.         } catch (ClassNotFoundException ex) {
  22.             Logger.getLogger(DBManager.class.getName()).log(Level.SEVERE, null, ex);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement