Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.Daniel.knockbackffa.MySQL;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.Bukkit;
- import com.mysql.jdbc.Statement;
- public class MySQL {
- public static String password = "";
- public static String database = "";
- public static String user = "";
- public static String host = "";
- public static int port = 3306;
- public static Connection con;
- public static void connect(){
- if(!isConnect()){
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host +":" + port + "/" + database, user, password);
- Bukkit.getConsoleSender().sendMessage("§aVerbindung zu MySQL wurde hergestellt!");
- } catch(SQLException e){
- e.printStackTrace();
- }
- }
- }
- public static void disconnect(){
- if(isConnect()){
- try {
- con.close();
- Bukkit.getConsoleSender().sendMessage("§cVerbindung zu MySQL fehlgeschlagen!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnect(){
- return con != null;
- }
- public static void createTable(){
- if(isConnect()){
- try {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Stats (Player VARCHAR(100), UUID VARCHAR(100), Kills INT(100), Deaths INT(100))");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void update(String qry){
- if(isConnect()){
- try {
- con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static ResultSet getResult(String qry){
- if(isConnect()){
- try {
- return con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement