Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package simpledatabasefx.connectdb;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.SQLException;
  11.  
  12. /**
  13.  *
  14.  * @author Moseleyes
  15.  */
  16. public class DataBaseConnect {
  17.     private static Connection connect;
  18.     public static Connection tryConnect()
  19.     {
  20.             if(connect == null)
  21.         {
  22.             try {
  23.                 String url  ="jdbc:mysql://localhost:3306/universitas";
  24.                 String user = "root";
  25.                 String pass = "";
  26.            
  27.                 DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  28.                 connect = DriverManager.getConnection(url, user, pass);
  29.             } catch (SQLException ex) {
  30.             //Logger.getLogger(DatabaseConnect.class.getName()).log(Level.SEVERE, null, ex);
  31.                 System.out.println("WARNING: Can not create connection!");
  32.             }
  33.         }
  34.          return connect;
  35.    
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement