123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package me.km.databank;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import me.km.api.Module;
- import net.minecraft.util.text.TextFormatting;
- public class DataBank extends Module
- {
- private Connection c;
-
- public DataBank(String mname, String prefix, TextFormatting color)
- {
- super(mname, prefix, color);
- }
-
- public boolean openDataBankConnection(String user, String password)
- {
- c = null;
- try
- {
- // The newInstance() call is a work around for some broken Java implementations
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- c = DriverManager.getConnection("jdbc:mysql://localhost/minecraft?autoReconnect=true", user, password);
- this.sendToConsole("Die Verbindung wurde erfolgreich aufgebaut.");
- return true;
- }
- catch(SQLException | ClassNotFoundException | InstantiationException | IllegalAccessException ex)
- {
- this.sendWarningToConsole(ex.getMessage());
- return false;
- }
- }
-
- public void closeDataBankConnection()
- {
- try
- {
- c.close();
- this.sendToConsole("Die Verbindung wurde erfolgreich unterbrochen.");
- }
- catch (SQLException ex)
- {
- this.sendWarningToConsole(ex.getMessage());
- }
- catch (NullPointerException ex)
- {
- }
- }
-
- public Connection getConnection()
- {
- /*try
- {
- if(c.isClosed())
- {
- openDataBankConnection();
- }
- }
- catch(SQLException ex)
- {
- }*/
- return c;
- }
- }
|