Advertisement
Guest User

Untitled

a guest
Oct 7th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. package me.eliteSchwein.PRcore_addon;
  2.  
  3. import java.io.PrintStream;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import com.mysql.jdbc.Driver;
  10.  
  11. public class MySQL
  12. {
  13. private String Host;
  14. private String Database;
  15. private String Username;
  16. private String Password;
  17. private Connection connection;
  18.  
  19. public MySQL(String host, String database, String username, String password)
  20. {
  21. this.Host = host;
  22. this.Database = database;
  23. this.Username = username;
  24. this.Password = password;
  25. }
  26.  
  27. public void Connect()
  28. {
  29. try
  30. {
  31. Class.forName("com.mysql.jdbc.Driver");
  32. }
  33. catch (ClassNotFoundException e1)
  34. {
  35. System.out.println("[MySQLAPI] Fehler 01");
  36. System.out.println("[MySQLAPI] Es fehlen benoetigte Klassen!");
  37. e1.printStackTrace();
  38. }
  39. String url = "jdbc:mysql://138.201.145.228:3306/PRmoney" + this.Database;
  40. try
  41. {
  42. this.connection = DriverManager.getConnection("jdbc:mysql://PureResolution.net/PRmoney", "", "");
  43. }
  44. catch (SQLException e2)
  45. {
  46. System.out.println("[MySQLAPI] Fehler 02");
  47. System.out.println("[MySQLAPI] Es ist ein Fehler bei der Verbindung aufgetreten!");
  48. e2.printStackTrace();
  49. }
  50. }
  51.  
  52. public void Disconnect()
  53. {
  54. try
  55. {
  56. if ((!this.connection.isClosed()) && (this.connection != null))
  57. {
  58. this.connection.close();
  59. System.out.println("[MySQLAPI] Die Verbindung zum MySQL-Server wurde erfolgreich getrennt!");
  60. }
  61. else
  62. {
  63. System.out.println("[MySQLAPI] Die Verbindung ist bereits getrennt!");
  64. }
  65. }
  66. catch (SQLException e3)
  67. {
  68. System.out.println("[MySQLAPI] Fehler 03");
  69. System.out.println("[MySQLAPI] Es ist ein Fehler beim trennen der Verbindung aufgetreten!");
  70. e3.printStackTrace();
  71. }
  72. }
  73.  
  74. public ResultSet GetResult(String command)
  75. {
  76. try
  77. {
  78. if (this.connection.isClosed()) {
  79. Connect();
  80. }
  81. Statement st = this.connection.createStatement();
  82. st.executeQuery(command);
  83. return st.getResultSet();
  84. }
  85. catch (SQLException e4)
  86. {
  87. System.out.println("[MySQLAPI] Fehler 04");
  88. System.out.println("[MySQLAPI] Es ist ein Fehler beim Ausfuehren des Befehls aufgetreten!");
  89. e4.printStackTrace();
  90. }
  91. return null;
  92. }
  93.  
  94. public void ExecuteCommand(String command)
  95. {
  96. try
  97. {
  98. if (this.connection.isClosed()) {
  99. Connect();
  100. }
  101. Statement st = this.connection.createStatement();
  102. st.executeUpdate(command);
  103. }
  104. catch (SQLException e5)
  105. {
  106. System.out.println("[MySQLAPI] Fehler 04");
  107. System.out.println("[MySQLAPI] Es ist ein Fehler beim Ausfuehren des Befehls aufgetreten!");
  108. e5.printStackTrace();
  109. }
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement