Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class MySQL {
- public String table;
- private String url;
- private String username;
- private String password;
- public Connection connection;
- private String TABLE;
- public String INSERT;
- public String UPDATE;
- public String UPDATE_COINS;
- public String UPDATE_NAME;
- public String UPDATE_STATS;
- public String SELECT;
- public String SELECT_COINS;
- public String SELECT_ORDER;
- public String SELECTALL;
- public String DELETE_PLAYER;
- public MySQL(String host, int port, String database, String username, String password, String table){
- this.url = ("jdbc:mysql://" + host + ":" + port + "/" + database);
- this.username = username;
- this.password = password;
- this.table = table;
- this.TABLE = ("CREATE TABLE IF NOT EXISTS " + table + "(uuid char(32), name char(16), unranked_wins int DEFAULT 0, ranked_wins int DEFAULT 0, premium_wins int DEFAULT 0, games_played int DEFAULT 0, play_time int DEFAULT 0, PRIMARY KEY(uuid))");
- this.INSERT = ("INSERT IGNORE INTO " + table + " values(?, ?, ?, ?, ?, ?, ?)");
- this.UPDATE = ("UPDATE " + table + " SET name=?, unranked_wins=?, ranked_wins=?, premium_wins=?, games_played=?, play_time=? where uuid=?");
- this.UPDATE_COINS = ("UPDATE coins SET coins=? where uuid=?");
- this.UPDATE_NAME = ("UPDATE " + table + " SET name=? where uuid=?");
- this.SELECT = ("SELECT * FROM " + table + " WHERE uuid=?");
- this.SELECT_COINS = ("SELECT coins FROM coins WHERE uuid=?");
- this.SELECT_ORDER = ("SELECT * FROM " + table + " ORDER BY %s DESC LIMIT 0,?");
- this.SELECTALL = ("SELECT * FROM " + table);
- this.DELETE_PLAYER = ("SELECT FROM " + table + " WHERE uuid=?");
- }
- public void close(){
- try {
- if (this.connection != null)
- this.connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void connect(){
- try {
- this.connection = DriverManager.getConnection(this.url, this.username, this.password);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public Connection getConnection(){
- try {
- if (this.connection == null || (!this.connection.isValid(5))) connect();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return this.connection;
- }
- public void setupTable(){
- Connection localConnection = getConnection();
- try {
- localConnection.createStatement().executeUpdate(this.TABLE);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement