Advertisement
Guest User

Untitled

a guest
Apr 13th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1.  
  2. public class MySQL {
  3.  
  4. private String HOST = "";
  5. private String DATABASE = "";
  6. private String USER = "";
  7. private String PASSWORD = "";
  8. private Connection con;
  9.  
  10. public MySQL(String host, String database, String user, String password) {
  11.  
  12. this.HOST = host;
  13. this.DATABASE = database;
  14. this.USER = user;
  15. this.PASSWORD = password;
  16.  
  17. }
  18.  
  19. public void connect() {
  20. try {
  21. this.con = ((Connection) DriverManager.getConnection("jdbc:mysql://" + this.HOST + ":3306/" + this.DATABASE + "?autoReconnect=true", this.USER, this.PASSWORD));
  22. } catch (Exception localException) {
  23. }
  24. }
  25.  
  26. public void close() {
  27. try {
  28. if (this.con != null) {
  29. this.con.close();
  30. }
  31. } catch (Exception localException) {
  32. }
  33. }
  34.  
  35. public void update(String qry) {
  36. try {
  37. Statement st = (Statement) this.con.createStatement();
  38. st.executeUpdate(qry);
  39. st.close();
  40. } catch (Exception localException) {
  41. }
  42. }
  43.  
  44. public ResultSet query(String qry) {
  45.  
  46. ResultSet rs = null;
  47.  
  48. try {
  49. Statement st = (Statement) this.con.createStatement();
  50. rs = st.executeQuery(qry);
  51. } catch (Exception localException) {
  52. }
  53. return rs;
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement