Advertisement
Guest User

Untitled

a guest
Apr 17th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. [13/04/2016 14:44:40] Naizox | Dev': connection = DriverManager.getConnection(url_base + host, username, passeword);
  2. [13/04/2016 14:46:13] Naizox | Dev': package fr.littlemc.api.mysql;
  3.  
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.SQLException;
  7.  
  8. import net.md_5.bungee.BungeeCord;
  9.  
  10. public class MySQL {
  11. private static String url_base = "jdbc:mysql://";
  12. private static String host = "localhost/******";
  13. private static String username = "*****";
  14. private static String passeword = "*******";
  15. private static Connection connection;
  16.  
  17. public static Connection getConnection() {
  18. return connection;
  19. }
  20.  
  21. public static boolean isConnected() {
  22. try {
  23. if ((connection == null) || (connection.isClosed())) {
  24. return false;
  25. }
  26. return true;
  27. } catch (SQLException e) {
  28. e.printStackTrace();
  29. }
  30. return false;
  31. }
  32.  
  33. @SuppressWarnings("deprecation")
  34. public static void connection() {
  35. if (!isConnected()) {
  36. try {
  37. BungeeCord.getInstance().getConsole()
  38. .sendMessage("§7[§eLittleAPI§7] §aTentative de connexion a la base de donnée ...");
  39. Class.forName("com.mysql.jdbc.Driver");
  40. connection = DriverManager.getConnection(url_base + host, username, passeword);
  41. BungeeCord.getInstance().getConsole().sendMessage("§7[§eLittleAPI§7] §aConnexion réussie !");
  42. } catch (SQLException e) {
  43. e.printStackTrace();
  44. } catch (ClassNotFoundException e) {
  45. e.printStackTrace();
  46. }
  47. }
  48. }
  49.  
  50. public static void deconnection() {
  51. if (isConnected()) {
  52. try {
  53. connection.close();
  54. } catch (SQLException e) {
  55. e.printStackTrace();
  56. }
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement