Advertisement
Guest User

Untitled

a guest
May 21st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. package eu.pixeldream.api.sql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class MySQL {
  8.    
  9.     private static final String host = "localhost";
  10.    
  11.     private static final String port = "3306";
  12.    
  13.     private static final String database = "***";
  14.  
  15.     private static final String user = "***";
  16.    
  17.     private static final String pass = "***";
  18.        
  19.     public static Connection openConnection() {
  20.         try {
  21.             Class.forName("com.mysql.jdbc.Driver");
  22.         } catch (ClassNotFoundException e1) {
  23.             e1.printStackTrace();
  24.         }
  25.         try {
  26.             Connection conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, pass);
  27.             System.out.println("§2API is connected to the database");
  28.             return conn;
  29.         } catch (SQLException e) {
  30.             System.out.println("§4The connection to the database failed");
  31.             e.printStackTrace();
  32.         }
  33.         return null;
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement