Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package simpledatabasefx.connectdb;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. /**
  8.  *
  9.  * @author arief
  10.  */
  11. public class DatabaseConnect {
  12.     private static Connection connect;
  13.     public static Connection tryConnect()
  14.     {
  15.             if(connect == null)
  16.         {
  17.             try {
  18.                 String url  ="jdbc:mysql://localhost:3306/universitas";
  19.                 String user = "root";
  20.                 String pass = "";
  21.            
  22.                 DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  23.                 connect = DriverManager.getConnection(url, user, pass);
  24.             } catch (SQLException ex) {
  25.             //Logger.getLogger(DatabaseConnect.class.getName()).log(Level.SEVERE, null, ex);
  26.                 System.out.println("WARNING: Can not create connection!");
  27.             }
  28.         }
  29.          return connect;
  30.    
  31.     }
  32. }