Advertisement
Guest User

Untitled

a guest
Oct 31st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. package de.clashside.main;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9.  
  10.  
  11.  
  12. public class mysql {
  13.  
  14.  
  15. public static String HOST = "localhost";
  16. public static String PORT = "3306";
  17. public static String DATABASE = "ClashSide";
  18. public static String USER = "root";
  19. public static String PASSWORD = "vX3CmZcJ";
  20. public static Connection con;
  21.  
  22.  
  23. public static void connect() {
  24. if(!isConnected()) {
  25. try {
  26. con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE, USER, PASSWORD);
  27. System.out.println("[MYSQL] Verbindung erfolreich aufgebaut");
  28. } catch (SQLException e) {
  29. e.printStackTrace();
  30. }
  31. }
  32.  
  33. }
  34.  
  35. public static void disconnect() {
  36. if(isConnected()) {
  37. try {
  38. con.close();
  39. System.out.println("[MYSQL] Wurde erfolgreich geschlossen");
  40. } catch (SQLException e) {
  41. e.printStackTrace();
  42. }
  43.  
  44. }
  45. }
  46.  
  47. public static boolean isConnected() {
  48. return (con == null ? false : true);
  49.  
  50. }
  51.  
  52.  
  53.  
  54. public static void createTable() {
  55.  
  56.  
  57. }
  58.  
  59.  
  60. public static ResultSet getResult(String qry) {
  61. try {
  62. PreparedStatement ps = con.prepareStatement(qry);
  63. return ps.executeQuery();
  64. } catch (SQLException e) {
  65. e.printStackTrace();
  66. }
  67. return null;
  68. }
  69.  
  70.  
  71. public static PreparedStatement getStatement(String sql) {
  72. if(isConnected()){
  73. PreparedStatement ps;
  74. try {
  75. ps = con.prepareStatement(sql);
  76. return ps;
  77. } catch (SQLException e) {
  78. e.printStackTrace();
  79. }
  80. }
  81.  
  82. return null;
  83. }
  84. public static void Update(String qry){
  85. try{
  86. Statement stmt = con.createStatement();
  87. stmt.executeUpdate(qry);
  88. }catch(Exception e){
  89. e.printStackTrace();
  90. }
  91. }
  92.  
  93. public static ResultSet Query(String query) throws SQLException {
  94. Statement statement = con.createStatement();
  95. return statement.executeQuery(query);
  96. }
  97.  
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement