SHARE
TWEET

Untitled

a guest Jul 20th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package de.teamsoul.main.mysql;
  2.  
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6.  
  7. public class methoden_coinsystem {
  8.  
  9.     public static boolean UserExists(String UID) {
  10.         try {
  11.             PreparedStatement ps = mysql.getConnection().prepareStatement("SELECT * FROM CoinSystem WHERE UID = ?");
  12.             ps.setString(1, UID);
  13.             ResultSet rs = ps.executeQuery();
  14.             return rs.next();
  15.         } catch (SQLException e) {
  16.             e.printStackTrace();
  17.         }
  18.         return false;
  19.     }
  20.  
  21.     public static void addCoins(int Coins, String UID, String Name) {
  22.  
  23.         if (UserExists(UID)) {
  24.  
  25.             try {
  26.                 PreparedStatement ps_upCoins = mysql.getConnection().prepareStatement("UPDATE CoinSystem SET Coins = Coins + ? WHERE UID = ?");
  27.                 ps_upCoins.setInt(1, Coins);
  28.                 ps_upCoins.setString(2, UID);
  29.                 ps_upCoins.executeUpdate();
  30.  
  31.                 PreparedStatement ps_upName = mysql.getConnection().prepareStatement("UPDATE CoinSystem SET Name = ? WHERE UID = ?");
  32.                 ps_upName.setString(1, Name);
  33.                 ps_upName.setString(2, UID);
  34.                 ps_upName.executeUpdate();
  35.             } catch (SQLException e) {
  36.                 e.printStackTrace();
  37.             }
  38.  
  39.         } else {
  40.  
  41.             try {
  42.                 PreparedStatement ps = mysql.getConnection().prepareStatement("INSERT INTO CoinSystem (Name,UID,Coins,DailyCoinsAvailable) VALUES (?,?,?,?)");
  43.                 ps.setString(1, Name);
  44.                 ps.setString(2, UID);
  45.                 ps.setInt(3, Coins);
  46.                 ps.setBoolean(4, true);
  47.                 ps.executeUpdate();
  48.             } catch (SQLException e) {
  49.                 e.printStackTrace();
  50.             }
  51.  
  52.         }
  53.  
  54.     }
  55.  
  56.     public static void removeCoins(String UID, int Coins) {
  57.         if (UserExists(UID)) {
  58.             try {
  59.                 PreparedStatement ps_check = mysql.getConnection().prepareStatement("SELECT Coins FROM CoinSystem WHERE UID = ?");
  60.                 ResultSet rs = ps_check.executeQuery();
  61.                 if (rs.getInt("Coins") >= Coins) {
  62.  
  63.                     PreparedStatement ps_remove = mysql.getConnection().prepareStatement("UPDATE CoinSystem SET Coins = Coins - ? WHERE UID = ?");
  64.                     ps_remove.setInt(1, Coins);
  65.                     ps_remove.setString(2, UID);
  66.                     ps_remove.executeUpdate();
  67.  
  68.                 }
  69.             } catch (SQLException e) {
  70.                 e.printStackTrace();
  71.             }
  72.         }
  73.     }
  74.  
  75.     public static boolean ifDailyBonusAvailable(String UID) {
  76.         try {
  77.             PreparedStatement ps = mysql.getConnection().prepareStatement("SELECT DailyCoinsAvailable FROM CoinSystem WHERE UID = \"?\"");
  78.             ps.setString(1, UID);
  79.             ResultSet rs = ps.executeQuery();
  80.             return rs.next();
  81.         } catch (SQLException e) {
  82.             e.printStackTrace();
  83.         }
  84.         return false;
  85.     }
  86.  
  87.     public static void deactivateDailyBonus(String UID) {
  88.         try {
  89.             PreparedStatement ps = mysql.getConnection().prepareStatement("UPDATE `CoinSystem` SET `DailyCoinsAvailable`='0' WHERE UID = ?");
  90.             ps.setString(1, UID);
  91.             ps.executeUpdate();
  92.         } catch (SQLException e) {
  93.             e.printStackTrace();
  94.         }
  95.     }
  96.  
  97. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top