Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lobbysystem.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import com.lobbysystem.LobbySystem;
- public class MySQLConnection {
- /* Created by: Suders
- * Date: 15.12.2017
- * Time: 18:41:11
- * Location: BungeeBanSystem
- */
- private static final String port = LobbySystem.getMySQLConfigManager().getPort();
- private static final String ip = LobbySystem.getMySQLConfigManager().getHost();
- private static final String database = LobbySystem.getMySQLConfigManager().getDatabase();
- private static final String host = "jdbc:mysql://" + ip + ":" + port + "/" + database + "?autoReconnect";
- private static final String username = LobbySystem.getMySQLConfigManager().getUsername();
- private static final String password = LobbySystem.getMySQLConfigManager().getPassword();
- public static Connection connection;
- public static void connect() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection(host, username, password);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static boolean isConnected() {
- try {
- if(connection != null && !connection.isClosed()) {
- return true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static void close() {
- if(isConnected()) {
- try {
- connection.close();
- } catch (SQLException e) {}
- }
- }
- public static void update(String qry) {
- try {
- Statement st = connection.createStatement();
- st.executeUpdate(qry);
- st.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static ResultSet query(String qry) {
- ResultSet rs = null;
- try {
- Statement st = connection.createStatement();
- rs = st.executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement