Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.ToxicGaming.Bungee.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class MySQL {
- public String host;
- public String port;
- public String database;
- public String username;
- public Connection con;
- public void connect(String host, String port, String database, String username) {
- if (!isConnected()) {
- this.database = database;
- this.port = port;
- this.host = host;
- this.username = username;
- try {
- con = DriverManager.getConnection(
- "jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username,
- password);
- System.out.println("Verbindung zur Datenbank " + database + " wurde erfolgreich aufgebaut!");
- } catch (Exception e) {
- e.printStackTrace();
- System.out.println("Verbindung zur Datenbank " + database + " wurde nicht erfolgreich aufgebaut!");
- }
- }
- }
- public void disconnect() {
- if (isConnected()) {
- try {
- con.close();
- con = null;
- System.out.println("Verbindung zur Datenbank " + database + " wurde erfolgreich geschlossen!");
- } catch (SQLException e) {
- System.out.println("Verbindung zur Datenbank " + database + " wurde nicht erfolgreich geschlossen!");
- }
- }
- }
- public boolean isConnected() {
- return (con == null ? false : true);
- }
- public Connection getConnection() {
- return con;
- }
- public String password = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement