SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void updateDeaths(Player player, int kills, int deaths, boolean remove) {
  2.         int death = getDeaths(player);
  3.         deaths += death;
  4.         if (isUserExists(player)) {
  5.             try {
  6.                 PreparedStatement ps = MySQL.getConnection()
  7.                         .prepareStatement("UPDATE creepergames SET Deaths = (Deaths+1) WHERE Name = ?");
  8.                 ps.setString(1, player.getName());
  9.  
  10.                 ps.executeUpdate();
  11.             } catch (SQLException e) {
  12.                 // TODO Auto-generated catch block
  13.                 e.printStackTrace();
  14.             }
  15.         } else {
  16.             try {
  17.                 PreparedStatement ps = MySQL.getConnection()
  18.                         .prepareStatement("INSERT INTO creepergames (Name,Kills,Deaths) VALUES (?,?,?)");
  19.                 ps.setString(1, player.getName());
  20.                 ps.setInt(2, kills);
  21.                 ps.setInt(3, deaths);
  22.                 ps.executeUpdate();
  23.             } catch (SQLException e) {
  24.                 // TODO Auto-generated catch block
  25.                 e.printStackTrace();
  26.             }
  27.         }
  28.     }
  29.  
  30.     public static Integer getKills(Player player) {
  31.         try {
  32.             PreparedStatement ps = MySQL.getConnection()
  33.                     .prepareStatement("SELECT Kills FROM creepergames WHERE Name = ?");
  34.             ps.setString(1, player.getName());
  35.             ResultSet rs = ps.executeQuery();
  36.             while (rs.next()) {
  37.                 return rs.getInt("Kills");
  38.             }
  39.         } catch (SQLException e) {
  40.             e.printStackTrace();
  41.         }
  42.         return 0;
  43.     }
  44.  
  45.     public static Integer getDeaths(Player player) {
  46.         try {
  47.             PreparedStatement ps = MySQL.getConnection()
  48.                     .prepareStatement("SELECT Deaths FROM creepergames WHERE Name = ?");
  49.             ps.setString(1, player.getName());
  50.             ResultSet rs = ps.executeQuery();
  51.             while (rs.next()) {
  52.                 return rs.getInt("Deaths");
  53.             }
  54.         } catch (SQLException e) {
  55.             e.printStackTrace();
  56.         }
  57.         return 0;
  58.     }
  59. }
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