Advertisement
Guest User

MySQL - Class

a guest
Feb 24th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package net.bausucht.enrico.coinsystem;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8.  
  9. public class MySQL {
  10.  
  11. public static String host = "173.212.248.242";
  12. public static String port = "3306";
  13. public static String database = "Enrico_A007-BauSucht-JavaTest";
  14. public static String username = "Enrico_A007";
  15. public static String password = "i98B2fiaUrsQoPJQMsvN";
  16. public static Connection con;
  17.  
  18.  
  19. public static void connect() {
  20. if(!(isConnected())) {
  21. try {
  22. con = DriverManager.getConnection("jdbc::mysql:://" + host + ":" + port + "/" + database, username, password);
  23.  
  24. }catch(SQLException e) {
  25. e.printStackTrace();
  26. }
  27. }
  28. }
  29.  
  30. public static void disconnect() {
  31. if(isConnected()) {
  32. try {
  33. con.close();
  34. }catch(SQLException e) {
  35. e.printStackTrace();
  36. }
  37. }
  38.  
  39. }
  40.  
  41. public static boolean isConnected() {
  42. return(con == null ? false : true);
  43. }
  44.  
  45. public static void update(String qry) {
  46. try {
  47. PreparedStatement ps = con.prepareStatement(qry);
  48. ps.executeUpdate();
  49. } catch (SQLException e) {
  50. e.printStackTrace();
  51. }
  52.  
  53. }
  54.  
  55. public static ResultSet getResult(String qry) {
  56. PreparedStatement ps;
  57. try {
  58. ps = con.prepareStatement(qry);
  59. return ps.executeQuery();
  60. } catch (SQLException e) {
  61. e.printStackTrace();
  62. }catch (NullPointerException e) {
  63. e.printStackTrace();
  64. }
  65. return null;
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement