Advertisement
Guest User

Untitled

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