Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. package de.slixfx.slixchat.util;
  2.  
  3. import de.slixfx.slixchat.main.Main;
  4.  
  5. import java.sql.*;
  6.  
  7. /**
  8. * Created by SlixFX on 06.05.2017 with Heart <3.
  9. */
  10. public class MySQL {
  11.  
  12. public static String username;
  13. public static String password;
  14. public static String database;
  15. public static String host;
  16. public static String port;
  17. public static Connection con;
  18.  
  19. public static void connect() {
  20. if(!isConnected()) {
  21. try {
  22. con = DriverManager.getConnection("jdbc:mysql://" + host + ":3306/" + database, username, password);
  23. System.out.println(Main.getInstance().prefix + "MySQL Verbindung aufgebaut!");
  24. } catch (SQLException e) {
  25. e.printStackTrace();
  26. }
  27. }
  28. }
  29.  
  30. public static void close() {
  31. if(isConnected()) {
  32. try {
  33. con.close();
  34. } catch (SQLException e) {
  35. e.printStackTrace();
  36. }
  37. System.out.println(Main.prefix + "§aMySQL Verbindung geschlossen!");
  38. }
  39. }
  40.  
  41. public static boolean isConnected() {
  42. return con != null;
  43. }
  44.  
  45. public static void createTables() {
  46. /**
  47. * Syntax: Spielername, UUID, Ende, Grund
  48. */
  49. if(isConnected()) try {
  50. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Ranks (Rang VARCHAR(100), Prefix VARCHAR(1000), ChatColor VARCHAR(10))");
  51. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Players (UUID VARCHAR(100), Name VARCHAR(100), Rang VARCHAR(100))");
  52. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS CustomPrefix (UUID VARCHAR(100), Name VARCHAR(100), Prefix VARCHAR(1000), ChatColor VARCHAR(10))");
  53. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Servers (Server VARCHAR(100), Abkuerzung VARCHAR(10))");
  54. } catch (SQLException e) {
  55. e.printStackTrace();
  56. }
  57. }
  58.  
  59. public static void update(String qry) {
  60. if(isConnected()) {
  61. try {
  62. con.createStatement().executeUpdate(qry);
  63. } catch (SQLException e) {
  64. e.printStackTrace();
  65. }
  66. }
  67. }
  68.  
  69. public static ResultSet getResult(String qry) {
  70. if(isConnected()) {
  71. try {
  72. return con.createStatement().executeQuery(qry);
  73. } catch (SQLException e) {
  74. e.printStackTrace();
  75. }
  76. }
  77. return null;
  78. }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement