Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Connection;
- import java.sql.SQLException;
- import com.mysql.jdbc.Statement;
- public class Donation {
- public static void checkDonation(String username, Client c) throws SQLException {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- System.out.println("Where is your MySQL JDBC Driver?");
- e.printStackTrace();
- return;
- }
- Connection connection = null;
- Statement stmt = null;
- try {
- connection = DriverManager
- .getConnection("jdbc:mysql://:3306/","", "");
- } catch (SQLException e) {
- System.out.println("Connection Failed! Check output console");
- e.printStackTrace();
- return;
- }
- if (connection != null) {
- stmt = (Statement) connection.createStatement();
- String sql;
- sql = "SELECT productId FROM checkout WHERE playerName='" +username+ "' AND canClaim='1' AND storeId='54'";
- ResultSet rs = stmt.executeQuery(sql);
- while(rs.next()){
- int id = rs.getInt("item_id");
- switch(id) {
- case 20:
- /**
- * If person purchases product with number 20 (find product id in admin cp) this code executes
- */
- break;
- case 23:
- /**
- * If person purchases product with number 23 (find product id in admin cp) this code executes
- */
- break;
- }
- }
- sql = "UPDATE checkout SET canClaim = '2' WHERE playerName='" +username+ "' AND canClaim='1' AND storeId='54'";
- stmt.execute(sql);
- rs.close();
- stmt.close();
- connection.close();
- } else {
- System.out.println("Failed to make connection!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement