Advertisement
Guest User

Untitled

a guest
Jun 17th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. package de.yeah;
  2.  
  3. import java.sql.*;
  4.  
  5. public abstract class MySQL {
  6.  
  7. public static String ip = "QuickMC.net";
  8. public static String database = "Global";
  9. public static String user = "Global";
  10. public static String password = "av7Gs_01";
  11. public static String port = "3306";
  12. public static String prefix = "[StatsAPI] ";
  13. public static String table = getTable();
  14.  
  15. static Connection con;
  16.  
  17. public static void connect() {
  18. try {
  19. con = DriverManager.getConnection("jdbc:mysql://" + ip + ":" + port + "/" + database + "?autoReconnect=true", user, password);
  20. System.out.println(prefix + "Die Verbindung zur MySQL-Datenbank wurde hergestellt!");
  21. } catch (SQLException e) {
  22. System.err.println(prefix + "Die Verbindung zur MySQL-Datenbank ist fehlgeschlagen! Fehler: " + e.getMessage());
  23. }
  24. }
  25.  
  26. public static void disconnect() {
  27. try {
  28. if (con != null) {
  29. con.close();
  30. System.out.println(prefix + "Die Verbindung zur MySQL-Datenbank wurde erfolgreich beendet!");
  31. }
  32. } catch (SQLException e) {
  33. System.out.println(prefix + "Fehler beim beenden der Verbindung zur MySQL-Datenbank! Fehler: " + e.getMessage());
  34. }
  35. }
  36.  
  37.  
  38.  
  39. public static void update(String qry) {
  40. try {
  41. PreparedStatement ps = con.prepareStatement(qry);
  42. ps.executeUpdate();
  43. } catch (SQLException e) {
  44. System.err.println(prefix + "Fehler beim Updaten: " + e.getMessage());
  45. }
  46. }
  47.  
  48. public static ResultSet query(String qry) {
  49. ResultSet rs = null;
  50. try {
  51. Statement st = con.createStatement();
  52. rs = st.executeQuery(qry);
  53. } catch (SQLException e) {
  54. connect();
  55. System.err.println(prefix + "Fehler bei Querybenutzung: " + e.getMessage());
  56. }
  57. return rs;
  58. }
  59.  
  60. public static String getTable() {
  61. if (StatsAPI.status == Modus.FreeForAll) {
  62. String table = "FFAStats";
  63. return table;
  64. }
  65. if (StatsAPI.status == Modus.SurvivalGames) {
  66. String table = "SGStats";
  67. return table;
  68. }
  69. if (StatsAPI.status == Modus.JumpWars) {
  70. String table = "JWStats";
  71. return table;
  72. }
  73. if (StatsAPI.status == Modus.Maze) {
  74. String table = "MStats";
  75. return table;
  76. }
  77. return null;
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement