Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.imwazzix.antiff;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.entity.Player;
- public class SQLAPI {
- private String url_base, host, name, username, password;
- private Connection connection;
- public SQLAPI(String url_base, String host, String name, String username,
- String password) {
- this.url_base = url_base;
- this.host = host;
- this.name = name;
- this.username = username;
- this.password = password;
- }
- public void Connection() {
- if (!isConnected()) {
- try {
- connection = DriverManager.getConnection(url_base + host + "/"
- + name, username, password);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void Unconnection() {
- if (isConnected()) {
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- private boolean isConnected() {
- try {
- if (connection == null || connection.isClosed()
- || !connection.isValid(5)) {
- return false;
- } else {
- return true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- private Connection getConnection() {
- return connection;
- }
- public String getServer(Player p) {
- String server = null;
- try {
- PreparedStatement sts = getConnection().prepareStatement(
- "SELECT server FROM choixserveur WHERE player = ?");
- sts.setString(1, p.getName());
- ResultSet rs = sts.executeQuery();
- if (!rs.next()) {
- return server;
- }
- server = rs.getString("server");
- sts.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return server;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement