Advertisement
Guest User

Untitled

a guest
Jul 26th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. package de.codereader.verify.bot;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. public class MySQL {
  9.  
  10. private String HOST = "";
  11. private String DATABASE = "";
  12. private String USER = "";
  13. private String PASSWORD = "";
  14.  
  15. private Connection con;
  16.  
  17. public MySQL(String host, String database, String user, String password) {
  18. this.HOST = host;
  19. this.DATABASE = database;
  20. this.USER = user;
  21. this.PASSWORD = password;
  22. }
  23.  
  24.  
  25. public void connect() {
  26. try {
  27. con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USER, PASSWORD);
  28. System.out.println("[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
  29. } catch (SQLException e) {
  30. System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: " + e.getMessage());
  31. }
  32. }
  33.  
  34.  
  35. public void close() {
  36. try {
  37. if(con != null) {
  38. con.close();
  39. System.out.println("[MySQL] Die Verbindung zur MySQL wurde Erfolgreich beendet!");
  40. }
  41. } catch (SQLException e) {
  42. System.out.println("[MySQL] Fehler beim beenden der Verbindung zur MySQL! Fehler: " + e.getMessage());
  43. }
  44. }
  45.  
  46.  
  47. public void update(String qry) {
  48.  
  49. try {
  50. con.createStatement().executeUpdate(qry);
  51. } catch (SQLException e) {
  52. e.printStackTrace();
  53. }
  54.  
  55.  
  56. }
  57.  
  58.  
  59. public ResultSet getResults(String qry) {
  60.  
  61. try {
  62. return con.createStatement().executeQuery(qry);
  63. } catch (SQLException e) {
  64. e.printStackTrace();
  65. }
  66. return null;
  67. }
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement