Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. package de.skywars.main;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6.  
  7. import com.mysql.jdbc.Connection;
  8.  
  9. public class MySQL {
  10.  
  11. public static Connection con;
  12.  
  13.  
  14.  
  15. public static void connect() {
  16.  
  17. if(!isConnected()) {
  18. try {
  19. con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/SkyWars?autoReconnect=true" , "root" , "91245859");
  20. System.out.println("[MySQL] Verbindung an");
  21. } catch (SQLException e) {
  22. e.printStackTrace();
  23. }
  24. }
  25.  
  26.  
  27. }
  28.  
  29. public static void disconnect() {
  30.  
  31. if(isConnected()) {
  32. try {
  33. con.close();
  34. System.out.println("[MySQL] Verbindung aus");
  35. } catch (SQLException e) {
  36. e.printStackTrace();
  37. }
  38. }
  39.  
  40. }
  41.  
  42.  
  43. public static boolean isConnected() {
  44. return (con != null);
  45. }
  46.  
  47.  
  48. public static void createTable() {
  49. if(isConnected()) {
  50. try {
  51. con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS SkyWarsStats (Name VARCHAR(100), Kills int , Tode int);");
  52. } catch (SQLException e) {
  53. e.printStackTrace();
  54. }
  55. }
  56. }
  57.  
  58.  
  59. public static void update(String qry) {
  60. try {
  61. java.sql.Statement st = con.createStatement();
  62. st.executeUpdate(qry);
  63. st.close();
  64. } catch (SQLException e) {
  65. connect();
  66. System.err.println(e);
  67. }
  68. }
  69.  
  70.  
  71. public static ResultSet getResult(String qry) {
  72. if(isConnected()) {
  73. try {
  74. return con.createStatement().executeQuery(qry);
  75. } catch (SQLException e) {
  76. e.printStackTrace();
  77. }
  78. }
  79. return null;
  80. }
  81.  
  82.  
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement