Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gg.southgate.slobby.utils;
- import com.zaxxer.hikari.HikariConfig;
- import com.zaxxer.hikari.HikariDataSource;
- import com.zaxxer.hikari.pool.HikariPool;
- import gg.southgate.mrleaw.language.utils.LanguageData;
- import org.bukkit.Bukkit;
- import java.sql.*;
- import java.util.UUID;
- public class FirstJoinMySQL {
- private static String host = "localhost", username = "test", password = "Southgate2013", database = "test", port = "3306";
- private static Connection con;
- public static void connect() {
- HikariConfig config = new HikariConfig();
- config.setJdbcUrl(String.format("jdbc:mysql://%s:%s/%s", host, port, database));
- config.setUsername(username);
- config.setPassword(password);
- try {
- con = new HikariDataSource(config).getConnection();
- } catch (HikariPool.PoolInitializationException | SQLException e) {
- e.printStackTrace();
- }
- if (con != null)
- Bukkit.getConsoleSender().sendMessage(LanguageData.getPrefix() + "§afirstJoin-MySQL-Connection ready!");
- }
- public static void close() {
- if (isConnected()) {
- try {
- con.close();
- Bukkit.getConsoleSender().sendMessage(LanguageData.getPrefix() + "§cfirstJoin-MySQL-Connection closed!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected() {
- return con != null;
- }
- public static boolean isFirstJoin(UUID uuid) {
- try {
- PreparedStatement ps = con.prepareStatement("SELECT uuid FROM firstjoin WHERE uuid = ?");
- ps.setString(1, uuid.toString());
- ResultSet rs = ps.executeQuery();
- return rs.next();
- } catch (SQLException e) {
- e.printStackTrace();
- return false;
- }
- }
- public static void createTable() {
- if (isConnected()) {
- try {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT exists firstjoin\n" +
- "(\n" +
- " uuid VARCHAR(50) PRIMARY KEY NOT NULL\n" +
- ");");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void insert(UUID uuid) {
- try {
- PreparedStatement ps = con.prepareStatement("INSERT INTO firstjoin (uuid) VALUES (?)");
- ps.setString(1, uuid.toString());
- ps.execute();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement