Advertisement
Guest User

Untitled

a guest
Apr 15th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. package fr.eligames.api.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 Connection connection;
  13.  
  14. public static String username;
  15. public static String password;
  16. public static String database;
  17. public static String host;
  18. public static String port;
  19.  
  20. public static String tablePlayers = "players";
  21.  
  22. public static void connect() {
  23. if (!isConnected()) {
  24. try {
  25. connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username,
  26. password);
  27.  
  28. Bukkit.getConsoleSender().sendMessage("�a[�bEliBeta�a] �aConnexion MySQL effectu�e !");
  29. } catch (SQLException e) {
  30. e.printStackTrace();
  31.  
  32. Bukkit.getConsoleSender().sendMessage("�a[�bEliBeta�a] �cConnexion impossible !");
  33. }
  34. }
  35. }
  36.  
  37. public static void close() {
  38. if (isConnected()) {
  39. try {
  40. connection.close();
  41.  
  42. Bukkit.getConsoleSender().sendMessage("�a[�bEliGames�a] �6Connexion MySQL ferm�e !");
  43. } catch (SQLException e) {
  44. e.printStackTrace();
  45. }
  46. }
  47. }
  48.  
  49. public static boolean isConnected() {
  50. return connection != null;
  51. }
  52.  
  53. public static void update(String qry) {
  54. if (isConnected()) {
  55. try {
  56. connection.createStatement().executeUpdate(qry);
  57. } catch (SQLException e) {
  58. e.printStackTrace();
  59. }
  60. }
  61. }
  62.  
  63. public static ResultSet getResult(String qry) {
  64. if (isConnected()) {
  65. try {
  66. return connection.createStatement().executeQuery(qry);
  67. } catch (SQLException e) {
  68. e.printStackTrace();
  69. }
  70. }
  71.  
  72. return null;
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement