Advertisement
Guest User

Untitled

a guest
May 9th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import com.mysql.fabric.jdbc.FabricMySQLDriver;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5.  
  6. public class DBWorker {
  7.  
  8.     private static final String URL = "jdbc:mysql://localhost:3306/database";
  9.     private static final String USERNAME = "root";
  10.     private static final String PASSWORD = "root";
  11.     Connection connection;
  12.  
  13.     public DBWorker() {
  14.  
  15.         try {
  16.             java.sql.Driver driver = new FabricMySQLDriver();
  17.             DriverManager.registerDriver(driver);
  18.  
  19.             connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
  20.  
  21.             if (connection.isClosed()){
  22.                 throw new SQLException();
  23.             }
  24.  
  25.         } catch (SQLException e) {
  26.             e.printStackTrace();
  27.         }
  28.     }
  29.  
  30.     public Connection getConnection(){
  31.         return connection;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement