Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package io.frenchdev.MySQL;
- import java.sql.*;
- public class MySQL{
- public String table;
- private Connection connection;
- String url;
- String username;
- String password;
- private String TABLE;
- public String INSERT;
- public String UPDATE;
- public String SELECT;
- public String SELECTALL;
- public String DELETE_PLAYER;
- public MySQL(final String table, final String s, final int i, final String s3, final String username, final String password) {
- this.url = "jdbc:mysql://" + s + ":" + i + "/" + s3;
- this.username = username;
- this.password = password;
- this.table = table;
- this.TABLE = "CREATE TABLE IF NOT EXISTS " + table + "(id INT AUTO_INCREMENT PRIMARY KEY, Player VARCHAR(255), Kills INT(255), Deaths INT(255), Wins INT(255), Coins INT(255), WoolDestroyed INT(255), Stars INT(255), Level INT(255))";
- this.INSERT = "insert into " + table + " (Player, Kills, Deaths, Wins, Coins, WoolDestroyed, Stars, Level) values(?, ?, ?, ?, ?, ?,?, ?, ?, ?)";
- this.UPDATE = "update " + table + " set Kills=?,Deaths=?,Wins=?,Coins=?,WoolDestroyed=?,Stars=?,Level=? where Player=?";
- this.SELECT = "select * from " + table + " where Player=?";
- this.SELECTALL = "select * from " + table;
- this.DELETE_PLAYER = "delete from " + table + " where Player=?";
- }
- public void close() throws SQLException {
- this.connection.close();
- }
- public void connect() throws SQLException {
- this.connection = DriverManager.getConnection(this.url, this.username, this.password);
- }
- public Connection getConnection() throws SQLException {
- if (this.connection == null || !this.connection.isValid(5)) {
- this.connect();
- }
- return this.connection;
- }
- public void setupTable() throws SQLException {
- this.getConnection().createStatement().executeUpdate(this.TABLE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement