Advertisement
Guest User

Untitled

a guest
Aug 31st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. package fr.capi29.luceatolyaeconomie.sqlmanager;
  2.  
  3. import org.bukkit.entity.Player;
  4.  
  5. import java.sql.*;
  6. import java.util.UUID;
  7.  
  8. /**
  9. * Created by Vincent on 30/08/2017.
  10. */
  11. public class SqlConnection {
  12.  
  13. public SqlConnection(){}
  14.  
  15.  
  16. private Connection connection;
  17. private String urlbase, host, database, user, pass;
  18.  
  19. public SqlConnection(String urlbase,String host,String database,String user,String pass) {
  20. this.urlbase = urlbase;
  21. this.host = host;
  22. this.database = database;
  23. this.user = user;
  24. this.pass = pass;
  25. }
  26.  
  27. public void connection(){
  28. if(!isConnected ()) {
  29.  
  30. try {
  31. connection=DriverManager.getConnection (urlbase + host + "/" + database, user, pass);
  32. System.out.println ("CONNECTION OK");
  33. } catch (SQLException e) {
  34. e.printStackTrace ( );
  35. }
  36. }
  37. }
  38.  
  39. public void disconnect(){
  40.  
  41. if(isConnected ()) {
  42. try {
  43. connection.close ( );
  44. } catch (SQLException e) {
  45. e.printStackTrace ( );
  46. }
  47. }
  48. }
  49.  
  50. public boolean isConnected(){
  51.  
  52. return connection != null ;
  53. }
  54.  
  55.  
  56. public void createAccount(UUID uuid,Player player){
  57.  
  58. if(!hasAccount (uuid)){
  59.  
  60. try {
  61. PreparedStatement preparedStatement = connection.prepareStatement ("INSERT TO economie(uuid, coins)VALUES(?,?)");
  62. preparedStatement.setString (1, uuid.toString ());
  63. preparedStatement.setDouble (2, 100);
  64. preparedStatement.execute ();
  65. preparedStatement.close ();
  66.  
  67. player.sendMessage ("Votre compte est crée ! ");
  68.  
  69. } catch (SQLException e) {
  70. player.sendMessage ("pas fait");
  71. }
  72.  
  73. }
  74. }
  75.  
  76. public boolean hasAccount(UUID uuid){
  77.  
  78. try {
  79. PreparedStatement preparedStatement = connection.prepareStatement ("SELECT uuid FROM economie WHERE uuid = (?)");
  80. preparedStatement.setString (1, uuid.toString ());
  81. ResultSet resultSet = preparedStatement.executeQuery ();
  82. boolean hasAccount = resultSet.next ();
  83. preparedStatement.close ();
  84. return hasAccount;
  85.  
  86. } catch (SQLException e) {
  87. e.printStackTrace ( );
  88. }
  89.  
  90. return false;
  91. }
  92.  
  93. public double getCoins(){
  94. return 0;
  95.  
  96. }
  97.  
  98. public void addMoney(UUID uuid, double coins){
  99.  
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement