Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.github.Viduality.VSkyblock;
- import com.github.Viduality.VSkyblock.Utilitys.ConfigShorts;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class MySQLConnector{
- private VSkyblock plugin = VSkyblock.getInstance();
- /*
- * returns the username of the mysql user
- */
- public String getDbUser() {
- return plugin.getConfig().getString("database.user");
- }
- /*
- * reutrns the mysql password
- */
- public String getDbPasswort() {
- return plugin.getConfig().getString("database.password");
- }
- /*
- * returns the database name
- */
- private String getDatabase() {
- return plugin.getConfig().getString("database.database");
- }
- /*
- * returns the database url
- */
- public String getDbUrl() {
- return plugin.getConfig().getString("database.url");
- }
- /*
- * returns the database url
- */
- public String getDbUrlParameters() {
- return plugin.getConfig().getString("database.url-parameters");
- }
- public void initConnection() {
- ConfigShorts.loaddefConfig();
- if (getDatabase() != null && !getDatabase().isEmpty()) {
- initTables();
- }
- }
- public Connection getConnection() {
- try {
- return DriverManager.getConnection("jdbc:mysql://"
- + getDbUrl() + "/"
- + getDatabase(),
- getDbUser(),
- getDbPasswort());
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- protected void initTables() {
- Connection connection = getConnection();
- try {
- connection.createStatement().execute(
- "CREATE DATABASE IF NOT EXISTS " + getDatabase());
- connection.createStatement().execute(
- "CREATE TABLE IF NOT EXISTS VSkyblock_Player("
- + "playerid BIGINT AUTO_INCREMENT NOT NULL,"
- + "playername VARCHAR(50) NOT NULL,"
- + "uuid VARCHAR(100) UNIQUE NOT NULL,"
- + "island VARCHAR(100),"
- + "islandowner BOOLEAN NOT NULL DEFAULT 0,"
- + "ownerid VARCHAR(100),"
- + "kicked BOOLEAN NOT NULL DEFAULT 0,"
- + "PRIMARY KEY (playerid));");
- connection.createStatement().execute(
- "CREATE TABLE IF NOT EXISTS VSkyblock_Island("
- + "islandid BIGING AUTO_INCREMENT NOT NULL,"
- + "island VARCHAR(100) NOT NULL,"
- + "islandlevel VARCHAR(100),"
- + "FOREIGN KEY (island) REFERENCES VSkyblock_Player(island),"
- + "PRIMARY KEY (islandid))");
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- closeConnection(connection);
- }
- }
- public void closeConnection(Connection connection) {
- try {
- if (connection != null) {
- connection.close();
- } else {
- VSkyblock.getInstance().getLogger().warning("connection = null, VSkyblock can't close");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void close(){
- }
- }
Add Comment
Please, Sign In to add comment