Vinetos

Bukkit Dev' | #39 - Base de donnés - MySQL.java

Aug 13th, 2015
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4.  
  5. public class MySQL {
  6.  
  7. private static Connection connection;
  8. private static String url_base = "jdbc:mysql://", host = "minecraft23.omgserv.com/minecraft_464",
  9. username = "minecraft_464", passeword = "tutobdd";
  10.  
  11. public static Connection getConnection(){
  12. return connection;
  13. }
  14.  
  15. public static boolean isConnected(){
  16. try {
  17. if((connection == null) || (connection.isClosed())){
  18. return false;
  19. }else{
  20. return true;
  21. }
  22. } catch (SQLException e) {
  23. e.printStackTrace();
  24. }
  25. return false;
  26. }
  27.  
  28. public static void connection(){
  29. if(!isConnected()){
  30. try {
  31. connection = DriverManager.getConnection(url_base+host, username, passeword);
  32. } catch (SQLException e) {
  33. e.printStackTrace();
  34. }
  35. }
  36. }
  37.  
  38. public static void deconnection(){
  39. if(isConnected()){
  40. try {
  41. connection.close();
  42. } catch (SQLException e) {
  43. e.printStackTrace();
  44. }
  45. }
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment