Advertisement
Guest User

Untitled

a guest
Mar 12th, 2016
108
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.SnoEx.InterPvP.mysql;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. public class MySQL
  10. {
  11. public static String host = "localhost";
  12. public static String port = "3306";
  13. public static String database = "Inter";
  14. public static String username = "root";
  15. public static String password = "boxigogu";
  16. public static Connection con;
  17.  
  18. public static void connect()
  19. {
  20. if (!isConnected()) {
  21. try
  22. {
  23. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true",
  24. username, password);
  25. createTable();
  26. System.out.println("Verbunden");
  27. }
  28. catch (SQLException localSQLException) {}
  29. }
  30. }
  31.  
  32. public static void close()
  33. {
  34. try
  35. {
  36. if (con != null) {
  37. con.close();
  38. }
  39. }
  40. catch (SQLException localSQLException) {}
  41. }
  42.  
  43. public static void update(String qry)
  44. {
  45. try
  46. {
  47. Statement st = con.createStatement();
  48. st.executeUpdate(qry);
  49. st.close();
  50. }
  51. catch (SQLException e)
  52. {
  53. connect();
  54. }
  55. }
  56.  
  57. public static ResultSet query(String qry)
  58. {
  59. ResultSet rs = null;
  60. try
  61. {
  62. Statement st = con.createStatement();
  63. rs = st.executeQuery(qry);
  64. }
  65. catch (SQLException e)
  66. {
  67. connect();
  68. }
  69. return rs;
  70. }
  71.  
  72. public static boolean isConnected()
  73. {
  74. return con != null;
  75. }
  76.  
  77. static void createTable()
  78. {
  79. update("CREATE TABLE IF NOT EXISTS Player (User VARCHAR(16), Password VARCHAR(16))");
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement