Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package eu.tryjump.utils;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class MySQL {
- private static String host = "92.42.44.93";
- private static String password = "";
- private static String username = "";
- private static String database = "SkyWars";
- private static String port = "3066";
- private static Connection con;
- public static void connect() {
- try {
- if(!isConnected()) {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
- System.out.println("[MySQL] Connected to MySQL!");
- }
- } catch(SQLException e) {
- System.out.println("[MySQL] Connection failed! Error: " + e.getMessage());
- e.printStackTrace();
- }
- }
- public static void close() {
- try {
- if(con!=null) {
- con.close();
- System.out.println("[MySQL] Connection closed!");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void update(String qry) {
- try {
- PreparedStatement ps = con.prepareStatement(qry);
- ps.executeUpdate();
- ps.close();
- } catch (SQLException e) {
- connect();
- System.err.println(e);
- }
- }
- public static ResultSet query(String qry) {
- ResultSet rs = null;
- try {
- Statement ps = con.createStatement();
- rs=ps.executeQuery(qry);
- } catch (SQLException e) {
- connect();
- System.err.println(e);
- }
- return rs;
- }
- public static boolean isConnected() {
- if(con!=null) {
- return true;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement