Advertisement
Guest User

MySQL.java

a guest
Apr 19th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. package me.WingedMLGPro.API;
  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. private static Connection connection;
  11. public static String username = "mc19421";
  12. public static String password = IM NOT THAT DUMB
  13. public static String database = "mc19421";
  14. public static String host = "23.94.121.2";
  15. public static String port = "3306";
  16.  
  17. public static void connect() {
  18. if (!isConnected())
  19. try {
  20. connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  21. } catch (SQLException e) {
  22. e.printStackTrace();
  23. }
  24. }
  25.  
  26. public static void close()
  27. {
  28. if (isConnected())
  29. try {
  30. connection.close();
  31. } catch (SQLException e) {
  32. e.printStackTrace();
  33. }
  34. }
  35.  
  36. public static void update(String qry)
  37. {
  38. if (isConnected())
  39. try {
  40. connection.createStatement().executeUpdate(qry);
  41. } catch (SQLException e) {
  42. e.printStackTrace();
  43. }
  44. }
  45.  
  46. public static ResultSet getResult(String qry)
  47. {
  48. if (isConnected()) {
  49. try {
  50. return connection.createStatement().executeQuery(qry);
  51. } catch (SQLException e) {
  52. e.printStackTrace();
  53. }
  54. }
  55. return null;
  56. }
  57.  
  58. public static boolean isConnected() {
  59. return connection != null;
  60. }
  61.  
  62. public static void createTable() {
  63. if (isConnected())
  64. try {
  65. connection.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS SwiftyCreditsTest (UUID VARCHAR(100), PlayerName VARCHAR(100), Credits INT(10))");
  66. } catch (SQLException e) {
  67. e.printStackTrace();
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement