Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.xericker.mysteryboxes.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import me.xericker.mysteryboxes.config.Config.RConfig;
- import me.xericker.mysteryboxes.config.ConfigMgr;
- public class MySQL
- {
- private static Connection connection;
- public static void connect()
- {
- if (!ConfigMgr.config.getBoolean("mysql.enabled")) {
- return;
- }
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- String host = ConfigMgr.config.getString("mysql.host");
- String datebase = ConfigMgr.config.getString("mysql.datebase");
- String username = ConfigMgr.config.getString("mysql.username");
- String password = ConfigMgr.config.getString("mysql.password");
- connection = DriverManager.getConnection("jdbc:mysql://" + host + "/" + datebase + "?user=" + username + "&password=" + password + "");
- checkTables();
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- }
- }
- public static boolean columnExists(String table, String column)
- {
- try
- {
- ResultSet resultSet = query("SELECT " + column + " FROM " + table + ";");
- return resultSet != null;
- }
- catch (Exception exception) {}
- return false;
- }
- public static void checkTables() {}
- public static void update(String query)
- {
- try
- {
- if ((connection == null) || (connection.isClosed())) {
- connect();
- }
- PreparedStatement preparedStatement = connection.prepareStatement(query);
- preparedStatement.execute();
- preparedStatement.close();
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- }
- }
- public static ResultSet query(String query)
- {
- try
- {
- if ((connection == null) || (connection.isClosed())) {
- connect();
- }
- PreparedStatement preparedStatement = connection.prepareStatement(query);
- return preparedStatement.executeQuery();
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- }
- return null;
- }
- }
Add Comment
Please, Sign In to add comment