Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. package de.yussef.oop.oop;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8.  
  9. import com.mysql.jdbc.Driver;
  10.  
  11. public class MySQL {
  12.  
  13. public static String host,
  14. port,
  15. username,
  16. database,
  17. password;
  18. public static Connection con;
  19.  
  20. public MySQL(String host, String port, String username, String database, String password) {
  21. this.host = host;
  22. this.port = port;
  23. this.username = username;
  24. this.database = database;
  25. this.password = password;
  26. }
  27.  
  28. public static void connect() {
  29. if(!(isConnected())) {
  30. try {
  31. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username, password);
  32. System.out.println("MySQL Verbindung ist nun da");
  33. } catch (SQLException e) {
  34. e.printStackTrace();
  35. }
  36. }
  37. }
  38.  
  39. public static void disconnect() {
  40. try {
  41. if(isConnected()) {
  42. con.close();
  43. System.out.println("MySQL net mehr da");
  44. }
  45. } catch (SQLException e) {
  46. e.printStackTrace();
  47. }
  48. }
  49.  
  50. public static ResultSet getResult(String qry) {
  51. try {
  52. PreparedStatement ps = con.prepareStatement(qry);
  53. return ps.executeQuery();
  54. } catch (SQLException e) {
  55. e.printStackTrace();
  56. }
  57. return null;
  58. }
  59.  
  60. public static void update(String qry) {
  61. if(isConnected()) {
  62. try {
  63. PreparedStatement ps = con.prepareStatement(qry);
  64. ps.executeUpdate();
  65. } catch (SQLException e) {
  66. e.printStackTrace();
  67. }
  68. }
  69. }
  70.  
  71. public static void createTable() {
  72. if(isConnected()) {
  73. try {
  74. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Nick(name varchar(32),status int)");
  75. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Coins(name varchar(32),c int)");
  76. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Friends(uuid varchar(100),uuidfriend varchar(100),uuidanfrage varchar(100),status varchar(100))");
  77. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Rewards(uuid varchar(100), normal int, premium int)");
  78. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Koepfe(UUID varchar(100), Koepfe varchar(100), aktiv varchar(100))");
  79. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Gadgets(UUID varchar(100), Gadgets varchar(100), aktiv varchar(100))");
  80. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Friends(uuid varchar(100),uuidfriend varchar(100),uuidanfrage varchar(100),status varchar(100))");
  81. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS PlayerInfo(name varchar(32),bannedby varchar(32),mutedby varchar(32),uuid varchar(100),ip varchar(100))");
  82. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Toggle(uuid varchar(100),friends int,msg int,online int,jump int)");
  83. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Boots(UUID varchar(100), Boots varchar(100), aktiv varchar(100))");
  84. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Huete(UUID varchar(100), Huete varchar(100), aktiv varchar(100))");
  85. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Lottery(uuid varchar(100), lose int)");
  86. } catch (SQLException e) {
  87. e.printStackTrace();
  88. }
  89. }
  90. }
  91.  
  92. public static boolean isConnected() {
  93. return (con == null ? false : true);
  94. }
  95.  
  96. // GETTER
  97.  
  98. public static Connection getCon() {
  99. return con;
  100. }
  101.  
  102. public static String getDatabase() {
  103. return database;
  104. }
  105.  
  106. public static String getHost() {
  107. return host;
  108. }
  109.  
  110. public static String getPassword() {
  111. return password;
  112. }
  113.  
  114. public static String getPort() {
  115. return port;
  116. }
  117.  
  118. public static String getUsername() {
  119. return username;
  120. }
  121.  
  122. // SETTER
  123.  
  124. public static void setCon(Connection con) {
  125. MySQL.con = con;
  126. }
  127.  
  128. public static void setDatabase(String database) {
  129. MySQL.database = database;
  130. }
  131.  
  132. public static void setHost(String host) {
  133. MySQL.host = host;
  134. }
  135.  
  136. public static void setPassword(String password) {
  137. MySQL.password = password;
  138. }
  139.  
  140. public static void setPort(String port) {
  141. MySQL.port = port;
  142. }
  143.  
  144. public static void setUsername(String username) {
  145. MySQL.username = username;
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement