Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.yussef.oop.oop;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import com.mysql.jdbc.Driver;
- public class MySQL {
- public static String host,
- port,
- username,
- database,
- password;
- public static Connection con;
- public MySQL(String host, String port, String username, String database, String password) {
- this.host = host;
- this.port = port;
- this.username = username;
- this.database = database;
- this.password = password;
- }
- public static void connect() {
- if(!(isConnected())) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username, password);
- System.out.println("MySQL Verbindung ist nun da");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void disconnect() {
- try {
- if(isConnected()) {
- con.close();
- System.out.println("MySQL net mehr da");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static ResultSet getResult(String qry) {
- try {
- PreparedStatement ps = con.prepareStatement(qry);
- return ps.executeQuery();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- public static void update(String qry) {
- if(isConnected()) {
- try {
- PreparedStatement ps = con.prepareStatement(qry);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void createTable() {
- if(isConnected()) {
- try {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Nick(name varchar(32),status int)");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Coins(name varchar(32),c int)");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Friends(uuid varchar(100),uuidfriend varchar(100),uuidanfrage varchar(100),status varchar(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Rewards(uuid varchar(100), normal int, premium int)");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Koepfe(UUID varchar(100), Koepfe varchar(100), aktiv varchar(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Gadgets(UUID varchar(100), Gadgets varchar(100), aktiv varchar(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Friends(uuid varchar(100),uuidfriend varchar(100),uuidanfrage varchar(100),status varchar(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS PlayerInfo(name varchar(32),bannedby varchar(32),mutedby varchar(32),uuid varchar(100),ip varchar(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Toggle(uuid varchar(100),friends int,msg int,online int,jump int)");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Boots(UUID varchar(100), Boots varchar(100), aktiv varchar(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Huete(UUID varchar(100), Huete varchar(100), aktiv varchar(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Lottery(uuid varchar(100), lose int)");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected() {
- return (con == null ? false : true);
- }
- // GETTER
- public static Connection getCon() {
- return con;
- }
- public static String getDatabase() {
- return database;
- }
- public static String getHost() {
- return host;
- }
- public static String getPassword() {
- return password;
- }
- public static String getPort() {
- return port;
- }
- public static String getUsername() {
- return username;
- }
- // SETTER
- public static void setCon(Connection con) {
- MySQL.con = con;
- }
- public static void setDatabase(String database) {
- MySQL.database = database;
- }
- public static void setHost(String host) {
- MySQL.host = host;
- }
- public static void setPassword(String password) {
- MySQL.password = password;
- }
- public static void setPort(String port) {
- MySQL.port = port;
- }
- public static void setUsername(String username) {
- MySQL.username = username;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement