Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.playgame.nickdetector.sql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class sql {
- public static String host = "localhost";
- public static int port = 3306;
- public static String database = "test";
- public static String username = "root";
- public static String password = "test";
- public static Connection con;
- public static void connect(){
- if(!isConnected()){
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + "?autoReconnect=true", username, password);
- System.out.println("§4Die Verbindung zur MySQL Datenbank wurde erfolgreich hergestellt");
- } catch (SQLException e) {
- System.out.println("§4Die Verbindung zur MySQL Datenbank ist Fehlgeschlagen");
- e.printStackTrace();
- }
- }
- }
- public static void disconnect(){
- if(isConnected()){
- try {
- con.close();
- } catch (Exception e) {
- System.out.println("§4Die Verbindung zur MySQL Datenbank wurde geschlossen");
- }
- }
- }
- public static boolean isConnected(){
- return (con == null ? false : true);
- }
- public static Connection getConnection(){
- return con;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement