Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String host;
- public String port;
- public String database;
- public String username;
- public String password;
- private static Connection con;
- public MySQL(String host, String port, String database, String username, String password) {
- this.host = host;
- this.port = port;
- this.database = database;
- this.username = username;
- this.password = password;
- }
- public boolean isConnected() {
- return con != null;
- }
- public void connect() {
- if(!isConnected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
- System.out.println("Die Connection wurde hergestellt!");
- } catch(SQLException e) {
- System.out.println("Die Connection konnte nicht hergestellt werden!");
- System.out.println("Der Fehler ist:");
- System.out.println("" + e.getMessage());
- }
- }
- }
- public void disconnect() {
- if(isConnected()) {
- try {
- con.close();
- System.out.println("Die Connection wurde aufgehoben!");
- } catch(SQLException e) {
- System.out.println("Die Connection konnte nicht aufgehoben werden!");
- System.out.println("Der Fehler ist:");
- System.out.println("" + e.getMessage());
- }
- }
- }
- public void update(String qry) {
- if(isConnected()) {
- try {
- Statement stm = con.createStatement();
- stm.executeUpdate(qry);
- } catch(SQLException e) {
- System.out.println("Das Update konnte nicht ausgeführt werden!");
- System.out.println("Der Fehler ist:");
- System.out.println("" + e.getMessage());
- }
- }
- }
- public static Connection getConnection(){
- return con;
- }
- public ResultSet result(String qry) {
- ResultSet rs = null;
- update("create table if not exists BedWars(Name varchar(100), UUID varchar(100), Kills int, Deaths int, Wins int, brokenbeds int, Gespielt int)");
- if(isConnected()) {
- try {
- Statement stm = con.createStatement();
- rs = stm.executeQuery(qry);
- } catch(SQLException e) {
- System.out.println("Der ResultSet konnte nicht ausgeführt werden!");
- System.out.println("Der Fehler ist:");
- System.out.println("" + e.getMessage());
- }
- }
- return rs;
- }
- public void reconnect() {
- Timer timer = new Timer();
- timer.schedule(new TimerTask() {
- @Override
- public void run() {
- try {
- con.close();
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
- System.out.println("[Permissions] Reconnected!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }, 0, 10000*60*10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement