Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Class: MySQL
- * Package: de.centumvenatus.util.mysql
- */
- package de.centumvenatus.util.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- * @author SightCrafterHD
- */
- public class MySQL {
- private static String username = "lobby";
- private static String password = "WAZJpURtSae8YqZ6";
- private static String database = "minelabs";
- private static String host = "localhost";
- private static Integer port = 3306;
- private static Connection connection;
- public static Connection getConnection() {
- return connection;
- }
- public static Boolean isConnected() {
- if(connection == null) return false;
- try {
- if(connection.isClosed()) return false;
- } catch (SQLException ex) {
- Logger.getLogger(MySQL.class.getName()).log(Level.SEVERE, null, ex);
- return false;
- }
- return true;
- }
- public static Boolean connect() {
- if(!isConnected()) {
- try {
- connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
- return true;
- } catch (SQLException ex) {
- Logger.getLogger(MySQL.class.getName()).log(Level.SEVERE, null, ex);
- return false;
- }
- } else {
- return true;
- }
- }
- public static Boolean forceConnect() {
- try {
- connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
- return true;
- } catch (SQLException ex) {
- Logger.getLogger(MySQL.class.getName()).log(Level.SEVERE, null, ex);
- return false;
- }
- }
- public static Boolean close() {
- if(!isConnected()) {
- try {
- connection.close();
- return true;
- } catch (SQLException ex) {
- Logger.getLogger(MySQL.class.getName()).log(Level.SEVERE, null, ex);
- return false;
- }
- } else {
- return true;
- }
- }
- public static void update(String query) throws SQLException {
- if(isConnected()) {
- connection.createStatement().executeUpdate(query);
- }
- }
- public static ResultSet getResult(String query) throws SQLException {
- if(isConnected()) {
- return connection.createStatement().executeQuery(query);
- } else {
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement