Guest User

Untitled

a guest
Nov 27th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 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.  
  9. import com.mysql.jdbc.Connection;
  10.  
  11. import main.Main;
  12.  
  13. public class MySQL {
  14.  
  15. public static String username;
  16. public static String password;
  17. public static String database;
  18. public static String host;
  19. public static String port;
  20. public static Connection con;
  21.  
  22. public static void connect(){
  23. if(!isConnected()){
  24. try{
  25. con = (Connection) DriverManager.getConnection("jdbc:mysql://" + host + ":" + port +"/" + database, username, password);
  26. Bukkit.getConsoleSender().sendMessage(Main.getInstance().prefix + "MySQL verbunden!");
  27. }catch (SQLException e){
  28. e.printStackTrace();
  29. }
  30.  
  31. }
  32. }
  33. public static void close(){
  34. if(isConnected()){
  35. try {
  36. con.close();
  37. Bukkit.getConsoleSender().sendMessage(Main.getInstance().prefix + "MySQL verbindung getrennt!");
  38. } catch (SQLException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42.  
  43. }
  44.  
  45. public static boolean isConnected(){
  46. return con != null;
  47. }
  48.  
  49. public static void createTable(){
  50. if(!isConnected()){
  51. try{
  52. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS BannedPlayers (Spielername VARCHAR(100), Ende VARCHAR(100), Grund VARCHAR(100))");
  53. } catch (SQLException e){
  54. e.printStackTrace();
  55. }
  56. }
  57. }
  58.  
  59. public static void update(String qry){
  60. if(isConnected()){
  61. try{
  62. con.createStatement().executeUpdate(qry);
  63. }catch (SQLException e){
  64. e.printStackTrace();
  65. }
  66. }
  67.  
  68. }
  69.  
  70. public static ResultSet getResult(String qry){
  71. if(isConnected()){
  72. try {
  73. return con.createStatement().executeQuery(qry);
  74. } catch (SQLException e) {
  75. e.printStackTrace();
  76. }
  77. }
  78. return null;
  79. }
  80. }
Add Comment
Please, Sign In to add comment