Advertisement
Guest User

Untitled

a guest
Sep 11th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. public static File file = new File("plugins//KnockOUT//mySQL//mySQL.yml");
  2. public static YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  3. private static String HOST = cfg.getString("mySQL.Host");
  4. private static String DATABASE = cfg.getString("mySQL.Database");
  5. private static String USER = cfg.getString("mySQL.User");
  6. private static String PASSWORD = cfg.getString("mySQL.Password");
  7. private static Connection con;
  8.  
  9. public mySQL(String host, String database, String user, String password) {
  10. mySQL.HOST = host;
  11. mySQL.DATABASE = database;
  12. mySQL.USER = user;
  13. mySQL.PASSWORD = password;
  14. connect();
  15. }
  16. public static void connect() {
  17. try {
  18. con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true",
  19. USER, PASSWORD);
  20. System.out.println("[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
  21. } catch (SQLException e) {
  22. System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: " + e.getMessage());
  23. }
  24. }
  25. public void close() {
  26. try {
  27. if (con != null) {
  28. con.close();
  29. System.out.println("[MySQL] Die Verbindung zur MySQL wurde Erfolgreich beendet!");
  30. }
  31. } catch (SQLException e) {
  32. System.out.println("[MySQL] Fehler beim beenden der Verbindung zur MySQL! Fehler: " + e.getMessage());
  33. }
  34. }
  35. public static void update(String qry) {
  36. try {
  37. Statement st = con.createStatement();
  38. st.executeUpdate(qry);
  39. st.close();
  40. } catch (SQLException e) {
  41. connect();
  42. System.err.println(e);
  43. }
  44. }
  45. public static ResultSet query(String qry) {
  46. ResultSet rs = null;
  47. try {
  48. Statement st = con.createStatement();
  49. rs = st.executeQuery(qry);
  50. } catch (SQLException e) {
  51. connect();
  52. System.err.println(e);
  53. }
  54. return rs;
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement