Advertisement
Guest User

Untitled

a guest
Jul 31st, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. package mysql.impl;
  2.  
  3.  
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.Connection;
  7. import java.sql.SQLException;
  8.  
  9. import com.aldorps.model.Item;
  10. import com.aldorps.world.entity.impl.player.Player;
  11. import com.mysql.jdbc.Statement;
  12.  
  13. public class Donation {
  14.  
  15.   public static void checkDonation(String username, Player player) throws SQLException {
  16.     try {
  17.         Class.forName("com.mysql.jdbc.Driver");
  18.     } catch (ClassNotFoundException e) {
  19.         e.printStackTrace();
  20.         return;
  21.     }
  22.     Connection connection = null;
  23.     Statement stmt = null;
  24.  
  25.     try {
  26.         connection = DriverManager.getConnection("jdbc:mysql://158.69.223.170:3306/webstore","webstore", "aqyqPErAYvaGCajB");
  27.  
  28.     } catch (SQLException e) {
  29.         e.printStackTrace();
  30.         return;
  31.     }
  32.    
  33.     boolean space = false;
  34.  
  35.     if (connection != null) {
  36.         System.out.println(1);
  37.          stmt = (Statement) connection.createStatement();
  38.          String sql;
  39.          sql = "SELECT productId FROM checkout WHERE playerName='" +username+ "' AND canClaim='1'";
  40.          ResultSet rs = stmt.executeQuery(sql);
  41.          while(rs.next()){
  42.              int id  = rs.getInt("productId");
  43.              if(player.getInventory().getFreeSlots() >= 1) {
  44.                  switch(id) {
  45.                      case 17:
  46.                         //1$ scroll
  47.                          break;
  48.                      case 18:
  49.                         //5$ scroll
  50.                          break;
  51.                     case 19:
  52.                         //10$ scroll
  53.                          break;
  54.                     case 20:
  55.                         //25$ scroll
  56.                          break;
  57.                     case 21:
  58.                         //50$ scroll
  59.                          break;
  60.                     case 22:
  61.                         //100$ scroll
  62.                          break;
  63.                  }
  64.              } else {
  65.                  space = true;
  66.              }
  67.           }
  68.          if(!space) {
  69.              sql = "UPDATE checkout SET canClaim = '2' WHERE playerName='" +username+ "' AND canClaim='1'";
  70.              stmt.execute(sql);
  71.          }
  72.          rs.close();
  73.          stmt.close();
  74.          connection.close();
  75.  
  76.     } else {
  77.         System.out.println("Failed to make connection!");
  78.     }
  79.   }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement