Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zensiert;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.bukkit.Bukkit;
- import org.bukkit.plugin.Plugin;
- import com.mysql.jdbc.PreparedStatement;
- public class MySQL
- {
- private String HOST = "";
- private String DATABASE = "";
- private String USER = "";
- private String PASSWORD = "";
- private 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()
- {
- try
- {
- connection = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USER, PASSWORD);
- System.out.println("[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
- }
- catch (SQLException e)
- {
- System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: " + e.getMessage());
- }
- }
- public void close()
- {
- try
- {
- if(connection != null)
- {
- connection.close();
- System.out.println("[MySQL] Die Verbindung zur MySQL wurde Erfolgreich beendet!");
- }
- }
- catch (SQLException e)
- {
- System.out.println("[MySQL] Fehler beim beenden der Verbindung zur MySQL! Fehler: " + e.getMessage());
- }
- }
- public void update(String qry)
- {
- try
- {
- Statement st = connection.createStatement();
- st.executeUpdate(qry);
- st.close();
- }
- catch (SQLException e)
- {
- connect();
- System.err.println(e);
- }
- }
- public ResultSet query(String qry)
- {
- ResultSet rs = null;
- try
- {
- Statement st = connection.createStatement();
- rs = st.executeQuery(qry);
- }
- catch (SQLException e)
- {
- connect();
- System.err.println(e);
- }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement