Advertisement
Guest User

Untitled

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