Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. package me.Spleevtv.SkyUtils;
  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 myslq {
  10.  
  11. private String HOST;
  12. private String DATABASE;
  13. private String USER;
  14. private String PASSWORD;
  15. private String PORT;
  16.  
  17. private static Connection con;
  18.  
  19. public myslq(String host, String database,String user, String password, String port) {
  20. this.HOST = host;
  21. this.DATABASE = database;
  22. this.USER = user;
  23. this.PASSWORD = password;
  24. this.PORT = port;
  25.  
  26. connect();
  27. }
  28.  
  29.  
  30. public void connect() {
  31. try {
  32. con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":" + PORT + "/" + DATABASE, USER, PASSWORD);
  33. System.out.println(
  34. "[MySQL] Die Verbindung zur MySQL wurde hergestellt!");
  35. } catch (SQLException e) {
  36. System.out.println("[MySQL] Die Verbindung zur MySQL ist fehlgeschlagen! Fehler: "
  37. + e.getMessage());
  38. }
  39. }
  40.  
  41. public static 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: "
  49. + e.getMessage());
  50. }
  51. }
  52.  
  53. public void update(String qry) {
  54. try {
  55. Statement st = con.createStatement();
  56. st.executeUpdate(qry);
  57. st.close();
  58. } catch (SQLException e) {
  59. connect();
  60. System.err.println(e);
  61. }
  62. }
  63.  
  64. public ResultSet query(String qry) {
  65. ResultSet rs = null;
  66.  
  67. try {
  68. Statement st = con.createStatement();
  69. rs = st.executeQuery(qry);
  70. } catch (SQLException e) {
  71. connect();
  72. System.err.println(e);
  73. }
  74. return rs;
  75. }
  76. public static Connection getConnection() {
  77. return con;
  78. }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement