Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.SnoEx.InterPvP.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class MySQL
- {
- public static String host = "localhost";
- public static String port = "3306";
- public static String database = "Inter";
- public static String username = "root";
- public static String password = "boxigogu";
- public static Connection con;
- public static void connect()
- {
- if (!isConnected()) {
- try
- {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true",
- username, password);
- createTable();
- System.out.println("Verbunden");
- }
- catch (SQLException localSQLException) {}
- }
- }
- public static void close()
- {
- try
- {
- if (con != null) {
- con.close();
- }
- }
- catch (SQLException localSQLException) {}
- }
- public static void update(String qry)
- {
- try
- {
- Statement st = con.createStatement();
- st.executeUpdate(qry);
- st.close();
- }
- catch (SQLException e)
- {
- connect();
- }
- }
- public static ResultSet query(String qry)
- {
- ResultSet rs = null;
- try
- {
- Statement st = con.createStatement();
- rs = st.executeQuery(qry);
- }
- catch (SQLException e)
- {
- connect();
- }
- return rs;
- }
- public static boolean isConnected()
- {
- return con != null;
- }
- static void createTable()
- {
- update("CREATE TABLE IF NOT EXISTS Player (User VARCHAR(16), Password VARCHAR(16))");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement