Guest User

Untitled

a guest
May 2nd, 2017
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. package mertero.coinapi;
  2.  
  3.  
  4. import java.io.File;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.ResultSet;
  8.  
  9. import org.bukkit.configuration.file.FileConfiguration;
  10. import org.bukkit.configuration.file.YamlConfiguration;
  11.  
  12. import com.mysql.jdbc.Statement;
  13.  
  14. public class MySQL {
  15.  
  16. private String HOST = "";
  17. private String DATABASE = "";
  18. private String USER = "";
  19. private String PASSWORD = "";
  20. private Connection con;
  21.  
  22. public MySQL(String host, String database, String user, String password) {
  23.  
  24. File file = new File("plugins//CoinsAPI//config.yml");
  25. FileConfiguration mcfg = YamlConfiguration.loadConfiguration(file);
  26.  
  27. this.HOST = mcfg.getString("mysql.host");
  28. this.DATABASE = mcfg.getString("mysql.database");
  29. this.USER = mcfg.getString("mysql.user");
  30. this.PASSWORD = mcfg.getString("mysql.password");
  31.  
  32. }
  33.  
  34. public void connect() {
  35. try {
  36. this.con = ((Connection) DriverManager.getConnection("jdbc:mysql://" + this.HOST + ":3306/" + this.DATABASE + "?autoReconnect=false", this.USER, this.PASSWORD));
  37. System.out.println("[MySQL] verbindung erfolgreich aufgebaut!");
  38. } catch (Exception localException) {
  39. System.out.println("[MySQL] Verbindung zu " + this.HOST + " Fehlgeschlagen");
  40. }
  41. }
  42.  
  43. public void close() {
  44. try {
  45. if (this.con != null) {
  46. this.con.close();
  47. }
  48. } catch (Exception localException) {
  49. }
  50. }
  51.  
  52. public void update(String qry) {
  53. try {
  54. Statement st = (Statement) this.con.createStatement();
  55. st.executeUpdate(qry);
  56. st.close();
  57. } catch (Exception localException) {
  58. }
  59. }
  60.  
  61. public ResultSet query(String qry) {
  62.  
  63. ResultSet rs = null;
  64.  
  65. try {
  66. Statement st = (Statement) this.con.createStatement();
  67. rs = st.executeQuery(qry);
  68. } catch (Exception localException) {
  69. }
  70. return rs;
  71. }
  72. }
Add Comment
Please, Sign In to add comment