Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package de.hitslikepvp.stats;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. public class MySQL {
  9.  
  10. public static String host = "";
  11. public static String port = "";
  12. public static String database = "";
  13. public static String username = "";
  14. public static String passwort = "";
  15. public static Connection con;
  16.  
  17. public static void connect() {
  18. if(!isConnected()) {
  19. try {
  20. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, passwort);
  21. } catch (SQLException e) {
  22. e.printStackTrace();
  23. }
  24. }
  25. }
  26.  
  27. public static void disconnect() {
  28. if(isConnected()) {
  29. try {
  30. con.close();
  31. } catch (SQLException e) {
  32. e.printStackTrace();
  33. }
  34. }
  35. }
  36.  
  37. public static boolean isConnected() {
  38. return con != null;
  39. }
  40.  
  41. public static void createTable() {
  42. if(isConnected()) {
  43. try {
  44. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Stats (UUID VARCHAR (100), Kills INT (100), Deaths INT (100), KD INT (100))");
  45. } catch (SQLException e) {
  46. e.printStackTrace();
  47. }
  48. }
  49. }
  50.  
  51. public static ResultSet getResult(String qry) {
  52. try {
  53. return con.createStatement().executeQuery(qry);
  54. } catch (SQLException e) {
  55. e.printStackTrace();
  56. }
  57. return null;
  58. }
  59.  
  60. public static void update(String qry) {
  61. try {
  62. con.createStatement().executeUpdate(qry);
  63. } catch (SQLException e) {
  64. e.printStackTrace();
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement