Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mertero.coinapi;
- import java.io.File;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import com.mysql.jdbc.Statement;
- public class MySQL {
- private String HOST = "";
- private String DATABASE = "";
- private String USER = "";
- private String PASSWORD = "";
- private Connection con;
- public MySQL(String host, String database, String user, String password) {
- File file = new File("plugins//CoinsAPI//config.yml");
- FileConfiguration mcfg = YamlConfiguration.loadConfiguration(file);
- this.HOST = mcfg.getString("mysql.host");
- this.DATABASE = mcfg.getString("mysql.database");
- this.USER = mcfg.getString("mysql.user");
- this.PASSWORD = mcfg.getString("mysql.password");
- }
- public void connect() {
- try {
- this.con = ((Connection) DriverManager.getConnection("jdbc:mysql://" + this.HOST + ":3306/" + this.DATABASE + "?autoReconnect=false", this.USER, this.PASSWORD));
- System.out.println("[MySQL] verbindung erfolgreich aufgebaut!");
- } catch (Exception localException) {
- System.out.println("[MySQL] Verbindung zu " + this.HOST + " Fehlgeschlagen");
- }
- }
- public void close() {
- try {
- if (this.con != null) {
- this.con.close();
- }
- } catch (Exception localException) {
- }
- }
- public void update(String qry) {
- try {
- Statement st = (Statement) this.con.createStatement();
- st.executeUpdate(qry);
- st.close();
- } catch (Exception localException) {
- }
- }
- public ResultSet query(String qry) {
- ResultSet rs = null;
- try {
- Statement st = (Statement) this.con.createStatement();
- rs = st.executeQuery(qry);
- } catch (Exception localException) {
- }
- return rs;
- }
- }
Add Comment
Please, Sign In to add comment