Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.VealtBeast.main;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.UUID;
- public class MySQL {
- private static String host = "localhost";
- private static String database = "SoundSystem";
- private static String user = "SoundSystem";
- private static String password = "Gxz2m_19IGyptwsh";
- private static String port = "3306";
- private static Connection connection;
- public static void connect(){
- try {
- connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", user, password);
- System.out.println("[MySQL] Verbindung wurde erfolgreich aufgebaut");
- } catch (Exception e) {
- System.out.println("[MySQL] Deine MySQL Verbindung konnte NICHT hergestellt werden");
- }
- }
- public static void disconnect() {
- if(connection != null) {
- try {
- connection.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public static void Update(String query){
- try{
- Statement statement = connection.createStatement();
- statement.executeUpdate(query);
- statement.close();
- }catch(SQLException e){
- e.printStackTrace();
- disconnect();
- connect();
- }
- }
- public static void createUser(String UUID) {
- try {
- PreparedStatement statement = connection.prepareStatement("INSERT INTO SoundSystem values (?, true)");
- statement.setString(1, UUID);
- statement.execute();
- statement.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void createTable() {
- if(connection != null)
- Update("CREATE TABLE IF NOT EXISTS SoundSystem(uuid varchar(100), soundon boolean)");
- }
- public static boolean containsSoundSystem(String UUID) {
- try {
- PreparedStatement statement = connection.prepareStatement("SELECT * FROM SoundSystem WHERE uuid=?");
- statement.setString(1, UUID);
- ResultSet resultSet = statement.executeQuery();
- boolean con = resultSet.next();
- statement.close();
- resultSet.close();
- return con;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return true;
- }
- public static boolean isSoundOn(String UUID, String type) {
- if(type.equalsIgnoreCase("INVENTORY")) {
- try {
- PreparedStatement statement = connection.prepareStatement("SELECT * FROM SoundSystem WHERE uuid=?");
- statement.setString(1, UUID);
- ResultSet resultSet = statement.executeQuery();
- resultSet.next();
- boolean isSoundOn = resultSet.getBoolean("soundon");
- resultSet.close();
- statement.close();
- return isSoundOn;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return true;
- }else {
- try {
- PreparedStatement statement = connection.prepareStatement("SELECT * FROM SoundSystem WHERE uuid=?");
- statement.setString(1, UUID);
- ResultSet resultSet = statement.executeQuery();
- resultSet.next();
- boolean isSoundOn = resultSet.getBoolean("musicon");
- resultSet.close();
- statement.close();
- return isSoundOn;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return true;
- }
- }
- public static void setSound(String UUID, int i, String type) {
- if(type.equalsIgnoreCase("INVENTORY")) {
- Update("UPDATE SoundSystem SET soundon='" + i + "' WHERE uuid='"+ UUID +"'");
- }else if(type.equalsIgnoreCase("MUSIC")) {
- Update("UPDATE SoundSystem SET musicon='" + i + "' WHERE uuid='"+ UUID +"'");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement