Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.mike_lolz.shadoweco.utils.mysql;
- import me.mike_lolz.shadoweco.Core;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class MySQL {
- private static Connection connection;
- private static String username;
- private static String host;
- private static String password;
- private static String database;
- private static int port;
- public static Statement statement;
- public MySQL(){
- this.username = Core.getInstance().getConfig().getString("MySQL.username");
- this.host = Core.getInstance().getConfig().getString("MySQL.host");
- this.password = Core.getInstance().getConfig().getString("MySQL.password");
- this.database = Core.getInstance().getConfig().getString("MySQL.database");
- this.port = Core.getInstance().getConfig().getInt("MySQL.port");
- }
- public static void connect() throws SQLException,ClassNotFoundException{
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?user=" + username + "&password=" + password + "&autoReconnect=true");
- statement = connection.createStatement();
- if(connection != null && !connection.isClosed()){
- return;
- }
- synchronized (Core.getInstance()){
- if(connection !=null && !connection.isClosed()){
- return;
- }
- }
- }
- public static void createTable(){
- String balances = "CREATE TABLE IF NOT EXISTS Balances(" +
- "PlayerName VARCHAR(50)" +
- "PlayerUUID LONGTEXT" +
- "Balance DOUBLE";
- try {
- statement.executeUpdate(balances);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static Connection getConnection(){
- return connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement