Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String Host;
- public String Database;
- public String Username;
- public String Password;
- public Connection con;
- public void setMySQL(String Host, String Database, String Username, String Password) {
- this.Username = Username;
- this.Password = Password;
- this.Database = Database;
- this.Host = Host;
- }
- public void connect() {
- if(!isConnected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + Host + ":3306/" + Database + "?autoReconnect=true", Username, Password);
- Bukkit.getConsoleSender().sendMessage("[MySQL] Erfolgreich zur MySQL-Datenbank verbunden");
- } catch(SQLException e) {
- Bukkit.getConsoleSender().sendMessage("[MySQL] Es konnte nicht zur MySQL-Datenbank verbunden werden, bitte überprüfe deine Einstellungen");
- }
- }
- }
- public void close() {
- if(isConnected()) {
- try {
- con.close();
- con = null;
- Bukkit.getConsoleSender().sendMessage("[MySQL] Die MySQL Verbindung wurde getrennt");
- } catch(SQLException e) {
- Bukkit.getConsoleSender().sendMessage("[MySQL] Die MySQL Verbindung konnte nicht geschlossen werden");
- }
- }
- }
- public boolean isConnected() {
- return con != null;
- }
- public void update(String qry) {
- if(isConnected()) {
- try {
- con.createStatement().executeUpdate(qry);
- } catch(SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public ResultSet getResult(String qry) {
- try {
- return con.createStatement().executeQuery(qry);
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement