Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.tim.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class MySQL {
- private String user, password, host, database, port;
- private Connection con;
- public Connection getCon() {
- return con;
- }
- public void setCon(Connection con) {
- this.con = con;
- }
- public MySQL(String user, String password, String host, String database, String port) {
- this.user = user;
- this.password = password;
- this.host = host;
- this.database = database;
- this.port = port;
- }
- public void connect() {
- if(!isConnected()) {
- try {
- setCon(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database + "?autoReconnect=true", this.user, this.password));
- } catch (SQLException exc) {
- exc.printStackTrace();
- }
- }
- }
- public boolean isConnected() {
- return getCon() !=null;
- }
- public void close() {
- if(isConnected()) {
- try {
- getCon().close();
- } catch (SQLException exc) {
- exc.printStackTrace();
- }
- }
- }
- public void update(String qry) {
- if(isConnected()) {
- try {
- PreparedStatement ps = getCon().prepareStatement(qry);
- ps.executeUpdate();
- } catch (SQLException exc) {
- exc.printStackTrace();
- }
- }
- }
- public ResultSet query(String qry) {
- ResultSet rs = null;
- try {
- PreparedStatement ps = getCon().prepareStatement(qry);
- rs = ps.executeQuery();
- } catch (SQLException exc) {
- }
- return rs;
- }
- public void createTable() {
- update("CREATE TABLE IF NOT EXISTS Stats(UUID varchar(64), Points int, Kills int, Deaths int");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement