Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.melonmc.tntrun.Nick;
- import java.sql.*;
- /**
- * Created by User on 06.02.2017.
- */
- public class MySQL {
- public static String host = "localhost";
- public static String port = "3306";
- public static String database = "AutoNick";
- public static String username = "RufixHD";
- public static String password = "ldH39z7#";
- public static Connection con;
- public static void connect() {
- if(!isConnected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username, password);
- System.out.println("[MySQL] Verbindung aufgebaut!!!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void disconnect() {
- if(isConnected()) {
- try {
- con.close();
- System.out.println("Verbindung getrennt");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected() {
- return (con == null ? false : true);
- }
- public static int getNick(String uuid) {
- try {
- PreparedStatement ps = con.prepareStatement("SELECT Nick FROM Autonick WHERE UUID = ?");
- ps.setString(1, uuid);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- return rs.getInt("Nick");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement