Advertisement
Guest User

Untitled

a guest
Nov 15th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. package me.blaizerado.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. public class MySQL {
  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. connect();
  24. }
  25.  
  26. public void connect() {
  27. try {
  28. con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USER, PASSWORD);
  29. System.out.println("[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
  30. System.out.println("Loading mysql files");
  31. System.out.println("Bans:");
  32. System.out.println("---------------------");
  33. System.out.println("Stats");
  34. System.out.println("---------------------");
  35. System.out.println("Loading complet willkommen");
  36. } catch (SQLException e) {
  37. System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: " + e.getMessage());
  38. }
  39. }
  40.  
  41. public void close() {
  42. try {
  43. if(con != null) {
  44. con.close();
  45. System.out.println("[MySQL] Die Verbindung zur MySQL wurde Erfolgreich beendet!");
  46. }
  47. } catch (SQLException e) {
  48. System.out.println("[MySQL] Fehler beim beenden der Verbindung zur MySQL! Fehler: " + e.getMessage());
  49. }
  50. }
  51.  
  52. public void update(String qry) {
  53. try {
  54. Statement st = con.createStatement();
  55. st.executeUpdate(qry);
  56. st.close();
  57. } catch (SQLException e) {
  58. connect();
  59. System.err.println(e);
  60. }
  61. }
  62.  
  63. public ResultSet query(String qry) {
  64. ResultSet rs = null;
  65.  
  66. try {
  67. Statement st = con.createStatement();
  68. rs = st.executeQuery(qry);
  69. } catch (SQLException e) {
  70. connect();
  71. System.err.println(e);
  72. }
  73. return rs;
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement