Advertisement
Guest User

MySQL

a guest
Nov 24th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. package me.buzzfx.ffa.MySQL;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. import org.bukkit.Bukkit;
  9.  
  10. public class MySQL {
  11.  
  12. public static String passwd = "";
  13. public static String database = "test";
  14. public static String user = "root";
  15. public static String host = "localhost";
  16. public static int port = 3306;
  17. public static Connection con;
  18.  
  19. public static void connect() {
  20. if(!isConnect()) {
  21. try {
  22. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, passwd);
  23. Bukkit.getConsoleSender().sendMessage("§7[§3FFA§7] §a MySQL enabled.");
  24. } catch (SQLException e) {
  25. e.printStackTrace();
  26. }
  27. }
  28. }
  29.  
  30. public static void disconnect() {
  31. if(isConnect()) {
  32. try {
  33. con.close();
  34. Bukkit.getConsoleSender().sendMessage("§7[§3FFA§7] §a MySQL disabled.");
  35. } catch (SQLException e) {
  36. e.printStackTrace();
  37. }
  38. }
  39. }
  40.  
  41. public static boolean isConnect() {
  42. return con != null;
  43. }
  44.  
  45. public static void createTable() {
  46. if(isConnect()) {
  47. try {
  48. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS FFAStats (Player VARCHAR (100), UUID VARCHAR (100),Kills INT (100), Deaths INT (100)) ");
  49. } catch (SQLException e) {
  50. e.printStackTrace();
  51. }
  52. }
  53. }
  54.  
  55. public static void update(String qry) {
  56. if(isConnect()) {
  57. try {
  58. con.createStatement().executeUpdate(qry);
  59. } catch (SQLException e) {
  60. e.printStackTrace();
  61. }
  62. }
  63. }
  64.  
  65. public static ResultSet getResult(String qry) {
  66. if(isConnect()) {
  67. try {
  68. return con.createStatement().executeQuery(qry);
  69. } catch (SQLException e) {
  70. e.printStackTrace();
  71. }
  72. }
  73. return null;
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement