Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. import java.sql.DriverManager;
  2. import java.sql.ResultSet;
  3. import java.sql.Connection;
  4. import java.sql.SQLException;
  5.  
  6. import com.mysql.jdbc.Statement;
  7.  
  8. public class Donation {
  9.  
  10.     public static void checkDonation(String username, Client c) throws SQLException {
  11.         try {
  12.             Class.forName("com.mysql.jdbc.Driver");
  13.         } catch (ClassNotFoundException e) {
  14.             System.out.println("Where is your MySQL JDBC Driver?");
  15.             e.printStackTrace();
  16.             return;
  17.         }
  18.         Connection connection = null;
  19.         Statement stmt = null;
  20.  
  21.         try {
  22.             connection = DriverManager
  23.                     .getConnection("jdbc:mysql://:3306/","", "");
  24.  
  25.         } catch (SQLException e) {
  26.             System.out.println("Connection Failed! Check output console");
  27.             e.printStackTrace();
  28.             return;
  29.         }
  30.  
  31.         if (connection != null) {
  32.             stmt = (Statement) connection.createStatement();
  33.             String sql;
  34.             sql = "SELECT productId FROM checkout WHERE playerName='" +username+ "' AND canClaim='1' AND storeId='54'";
  35.             ResultSet rs = stmt.executeQuery(sql);
  36.             while(rs.next()){
  37.                 int id  = rs.getInt("item_id");
  38.                 switch(id) {
  39.                     case 20:
  40.                          /**
  41.                          * If person purchases product with number 20 (find product id in admin cp) this code executes
  42.                          */
  43.                         break;
  44.                     case 23:
  45.                          /**
  46.                          * If person purchases product with number 23 (find product id in admin cp) this code executes
  47.                          */
  48.                         break;
  49.                 }
  50.             }
  51.             sql = "UPDATE checkout SET canClaim = '2' WHERE playerName='" +username+ "' AND canClaim='1' AND storeId='54'";
  52.             stmt.execute(sql);
  53.             rs.close();
  54.             stmt.close();
  55.             connection.close();
  56.  
  57.         } else {
  58.             System.out.println("Failed to make connection!");
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement