Advertisement
Guest User

Untitled

a guest
Dec 8th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. package de.keinwlan.api;
  2.  
  3. import de.keinwlan.main.main;
  4. import de.keinwlan.storage.var;
  5. import org.bukkit.Bukkit;
  6.  
  7. import java.sql.*;
  8. import java.util.UUID;
  9. import java.util.logging.Logger;
  10.  
  11. public class MySQL {
  12.  
  13. public static String host = "localhost";
  14. public static String port = "3306";
  15. public static String database = "Lobby";
  16. public static String username = "root";
  17. public static String password = "";
  18.  
  19. public static Logger logger;
  20. public static int sched;
  21. public static Connection con;
  22.  
  23. public static boolean isconected() {
  24. return con != null;
  25. }
  26.  
  27. public static void connect() {
  28. if (!isconected()) {
  29. try {
  30. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconect=true", username, password);
  31. } catch (SQLException e) {
  32. }
  33. }
  34. }
  35.  
  36. public static void disconnect() {
  37. try {
  38. con.close();
  39. } catch (SQLException e) {
  40. }
  41. }
  42.  
  43. public static PreparedStatement getStatement(String sql) {
  44. if (isconected()) {
  45. PreparedStatement ps;
  46. try {
  47. ps = con.prepareStatement(sql);
  48. return ps;
  49. } catch (SQLException e) {
  50. e.printStackTrace();
  51. }
  52. }
  53. return null;
  54. }
  55.  
  56. public static void update(String qry) {
  57. try {
  58. Statement st = con.createStatement();
  59. st.executeUpdate(qry);
  60. st.close();
  61. } catch (SQLException e) {
  62. connect();
  63. System.err.println(e);
  64. }
  65. }
  66.  
  67. public static ResultSet getResult(String sql) {
  68. if (isconected()) {
  69. PreparedStatement ps;
  70. ResultSet rs;
  71. try {
  72. ps = getStatement(sql);
  73. rs = ps.executeQuery();
  74. return rs;
  75. } catch (SQLException e) {
  76. e.printStackTrace();
  77. }
  78. }
  79. return null;
  80. }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement