Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.jannis.bungee.utils;
- import net.md_5.bungee.api.ProxyServer;
- import java.sql.*;
- public class MySQL {
- Data data = new Data();
- private String HOST = "";
- private String DATABASE = "";
- private String USER = "";
- private String PASSWORD = "";
- public static Connection connection;
- public MySQL(String host, String database, String user, String password) {
- this.HOST = host;
- this.DATABASE = database;
- this.USER = user;
- this.PASSWORD = password;
- connect();
- }
- public void connect() {
- if(connection == null) {
- try {
- connection = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USER, PASSWORD);
- ProxyServer.getInstance().getConsole().sendMessage(data.getPrefix() +"Die Verbindung zur MySQL wurde erfolgreich hergestellt!");
- } catch(SQLException e) {
- ProxyServer.getInstance().getConsole().sendMessage(data.getPrefix() +"Die Verbindung zur MySQL konnte nicht hergestellt werden!");
- e.printStackTrace();
- }
- }
- }
- public void close() {
- if(connection != null) {
- try {
- connection.close();
- ProxyServer.getInstance().getConsole().sendMessage(data.getPrefix() +"Die Verbindung zur MySQL wurde erfolgreich geschlossen!");
- } catch(SQLException e) {
- ProxyServer.getInstance().getConsole().sendMessage(data.getPrefix() +"Fehler beim beenden der Verbindung zur MySQL!");
- e.printStackTrace();
- }
- }
- }
- public void update(String qry) {
- try {
- connection.createStatement().executeUpdate(qry);
- } catch(SQLException e) {
- e.printStackTrace();
- }
- }
- public ResultSet getResults(String qry) {
- try {
- return connection.createStatement().executeQuery(qry);
- } catch(SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- public static PreparedStatement getStatement(String sql) {
- if(connection != null) {
- PreparedStatement ps;
- try {
- ps = connection.prepareStatement(sql);
- return ps;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement