Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package CustomTokensMySQL
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.Bukkit;
- import org.bukkit.command.ConsoleCommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- public class MySQL
- {
- static Main plugin;
- public MySQL(Main main)
- {
- plugin = main;
- }
- public String host = "";
- public String port = "";
- public String database = "";
- public String username = "";
- public String password = "";
- public Connection con;
- public void connect()
- {
- this.host = plugin.getConfig().getString("CustomTokens.MySQL.Host");
- this.port = plugin.getConfig().getString("CustomTokens.MySQL.Port");
- this.database = plugin.getConfig().getString("CustomTokens.MySQL.Database");
- this.username = plugin.getConfig().getString("CustomTokens.MySQL.Username");
- this.password = plugin.getConfig().getString("CustomTokens.MySQL.Password");
- if (!connected()) {
- try
- {
- this.con = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
- Bukkit.getConsoleSender().sendMessage("[CustomTokens] MySQL - Connection constructed!");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- Bukkit.getConsoleSender().sendMessage("[CustomTokens] MySQL - Connection failed!");
- }
- }
- }
- public void disconnect()
- {
- if (connected()) {
- try
- {
- this.con.close();
- Bukkit.getConsoleSender().sendMessage("[CustomTokens] MySQL - Connection closed!");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public boolean connected()
- {
- if (this.con == null) {
- return false;
- }
- return true;
- }
- public void executeupdate(String qry)
- {
- try
- {
- PreparedStatement ps = this.con.prepareStatement(qry);
- ps.executeUpdate();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- public ResultSet gerResult(String qry)
- {
- try
- {
- PreparedStatement ps = this.con.prepareStatement(qry);
- return ps.executeQuery();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement