Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.keinwlan.api;
- import de.keinwlan.main.main;
- import de.keinwlan.storage.var;
- import org.bukkit.Bukkit;
- import java.sql.*;
- import java.util.UUID;
- import java.util.logging.Logger;
- public class MySQL {
- public static String host = "localhost";
- public static String port = "3306";
- public static String database = "Lobby";
- public static String username = "root";
- public static String password = "";
- public static Logger logger;
- public static int sched;
- public static Connection con;
- public static boolean isconected() {
- return con != null;
- }
- public static void connect() {
- if (!isconected()) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconect=true", username, password);
- } catch (SQLException e) {
- }
- }
- }
- public static void disconnect() {
- try {
- con.close();
- } catch (SQLException e) {
- }
- }
- public static PreparedStatement getStatement(String sql) {
- if (isconected()) {
- PreparedStatement ps;
- try {
- ps = con.prepareStatement(sql);
- return ps;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- public static void update(String qry) {
- try {
- Statement st = con.createStatement();
- st.executeUpdate(qry);
- st.close();
- } catch (SQLException e) {
- connect();
- System.err.println(e);
- }
- }
- public static ResultSet getResult(String sql) {
- if (isconected()) {
- PreparedStatement ps;
- ResultSet rs;
- try {
- ps = getStatement(sql);
- rs = ps.executeQuery();
- return rs;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement