Advertisement
Guest User

Untitled

a guest
Mar 27th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. import de.crackexception.nick.api.Data;
  8.  
  9. public class MySQL {
  10.  
  11. public static Connection c;
  12.  
  13. public static void connect(){
  14.  
  15. try{
  16. c = DriverManager.getConnection("jdbc:mysql://" + Data.host + ":3306" + "/" + Data.db + "?autoReconnect=true",Data.user,Data.pw);
  17. System.out.println("[MySQL] Connected.");
  18. } catch(SQLException e){
  19. System.out.println("[MySQL] Connection failed.");
  20. e.printStackTrace();
  21. }
  22. }
  23.  
  24. public static void disconnect() {
  25. if(c != null) {
  26. try {
  27. c.close();
  28. } catch (SQLException e) {
  29. e.printStackTrace();
  30. }
  31. }
  32. }
  33.  
  34. public static void Update(String qry) {
  35. try {
  36. Statement stmt = c.createStatement();
  37. stmt.executeUpdate(qry);
  38. stmt.close();
  39. } catch (SQLException ex) {
  40. ex.printStackTrace();
  41. disconnect();
  42. connect();
  43. }
  44. }
  45.  
  46. public static ResultSet query(String qry){
  47.  
  48. ResultSet rs = null;
  49. try{
  50.  
  51. Statement st = c.createStatement();
  52. rs = st.executeQuery(qry);
  53.  
  54. }catch(SQLException e){
  55.  
  56. connect();
  57. System.err.println(e);
  58.  
  59. }
  60. return rs;
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement