Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.capi29.luceatolyaeconomie.sqlmanager;
- import org.bukkit.entity.Player;
- import java.sql.*;
- import java.util.UUID;
- /**
- * Created by Vincent on 30/08/2017.
- */
- public class SqlConnection {
- public SqlConnection(){}
- private Connection connection;
- private String urlbase, host, database, user, pass;
- public SqlConnection(String urlbase,String host,String database,String user,String pass) {
- this.urlbase = urlbase;
- this.host = host;
- this.database = database;
- this.user = user;
- this.pass = pass;
- }
- public void connection(){
- if(!isConnected ()) {
- try {
- connection=DriverManager.getConnection (urlbase + host + "/" + database, user, pass);
- System.out.println ("CONNECTION OK");
- } catch (SQLException e) {
- e.printStackTrace ( );
- }
- }
- }
- public void disconnect(){
- if(isConnected ()) {
- try {
- connection.close ( );
- } catch (SQLException e) {
- e.printStackTrace ( );
- }
- }
- }
- public boolean isConnected(){
- return connection != null ;
- }
- public void createAccount(UUID uuid,Player player){
- if(!hasAccount (uuid)){
- try {
- PreparedStatement preparedStatement = connection.prepareStatement ("INSERT TO economie(uuid, coins)VALUES(?,?)");
- preparedStatement.setString (1, uuid.toString ());
- preparedStatement.setDouble (2, 100);
- preparedStatement.execute ();
- preparedStatement.close ();
- player.sendMessage ("Votre compte est crée ! ");
- } catch (SQLException e) {
- player.sendMessage ("pas fait");
- }
- }
- }
- public boolean hasAccount(UUID uuid){
- try {
- PreparedStatement preparedStatement = connection.prepareStatement ("SELECT uuid FROM economie WHERE uuid = (?)");
- preparedStatement.setString (1, uuid.toString ());
- ResultSet resultSet = preparedStatement.executeQuery ();
- boolean hasAccount = resultSet.next ();
- preparedStatement.close ();
- return hasAccount;
- } catch (SQLException e) {
- e.printStackTrace ( );
- }
- return false;
- }
- public double getCoins(){
- return 0;
- }
- public void addMoney(UUID uuid, double coins){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement