Advertisement
Guest User

Untitled

a guest
Feb 10th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. package de._Kally_.CoinSystem.MySQL;
  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.  
  9. public class MySQL {
  10.  
  11. static String host = "localhost";
  12. static String port = "3306";
  13. static String database = "plugins";
  14. static String username = "plugins";
  15. static String password = "ycwPzTt5uGarbkTz";
  16. public static Connection con;
  17. //Host: localhost
  18. //Port: 3306
  19. //Database: plugins
  20. //password: plugins
  21. //username: plugins
  22.  
  23. public static void connect() {
  24. if(!isConnected()) {
  25. try {
  26. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  27. System.out.println("[CoinSystem] MySQL verbunden!");
  28. } catch (SQLException e) {
  29.  
  30. e.printStackTrace();
  31. }
  32. }
  33. }
  34.  
  35. public static void disconnect() {
  36. if(isConnected()) {
  37. try {
  38. con.close();
  39. System.out.println("[CoinSystem] MySQL geschlossen!");
  40. } catch (SQLException e) {
  41.  
  42. e.printStackTrace();
  43. }
  44. }
  45. }
  46.  
  47. public static boolean isConnected() {
  48. return (con == null ? false :true);
  49. }
  50.  
  51. public static void update(String qry) {
  52.  
  53. try {
  54. PreparedStatement ps = con.prepareStatement(qry);
  55. ps.executeUpdate();
  56. } catch (SQLException e) {
  57.  
  58.  
  59. }
  60.  
  61.  
  62.  
  63. }
  64.  
  65. public static ResultSet getResult(String qry) {
  66. try {
  67. PreparedStatement ps = con.prepareStatement(qry);
  68. return ps.executeQuery();
  69. }catch(SQLException e) {
  70. e.printStackTrace();
  71. }
  72. return null;
  73. }
  74.  
  75. public static PreparedStatement getStatement(String sql){
  76. if(isConnected()){
  77. PreparedStatement ps;
  78. try {
  79. ps = con.prepareStatement(sql);
  80. return ps;
  81. } catch (SQLException e) {
  82. e.printStackTrace();
  83. }
  84. }
  85. return null;
  86.  
  87.  
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement