Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MySQL;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import com.mysql.jdbc.Connection;
- public class MySQL {
- public static java.sql.Connection con;
- public static Connection connection(String host, int port, String database, String user, String password) {
- try {
- con = (Connection)DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", user, password);
- Bukkit.getConsoleSender().sendMessage("§7[§aMySQL§7] §aDatenbankverbindung hergestellt.");
- } catch (SQLException e) {
- Bukkit.getConsoleSender().sendMessage("§7[§aMySQL§7] §cDatenbankverbindung konnte nicht hergestellt werden: " + e.getMessage());
- e.printStackTrace();
- }
- return (Connection) con;
- }
- public static void disconnect() {
- try {
- con.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static boolean hasConnection() {
- if (con != null) {
- return true;
- }
- return false;
- }
- public static void connect() {
- try {
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/***autoReconnect=true", "benutzername", "pw");
- }
- catch (SQLException ex) {
- Logger.getLogger(MySQL.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public static void close() {
- if (con != null) {
- try {
- con.close();
- }
- catch (SQLException ex) {
- Logger.getLogger(MySQL.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- public static void createTable() {
- try {
- PreparedStatement ps = con.prepareStatement("CREATE TABLE IF NOT EXISTS Gundula (UUID VARCHAR(100), Zeit VARCHAR(100))");
- ps.executeUpdate();
- ps.close();
- }
- catch (SQLException ps) {
- // empty catch block
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement