Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package engine.util;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.Iterator;
- import game.Client;
- public class SQL
- {
- public static Connection con = null;
- public static Statement stmt;
- public static boolean printed = false;
- public static boolean isConnected = false;
- private static Iterator e;
- public static boolean createConnection()
- {
- try
- {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- con = DriverManager.getConnection(
- "jdbc:mysql://184.22.222.172/taintedx_points", "taintedx_points", "hurrdurr");
- stmt = con.createStatement();
- isConnected = true;
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- isConnected = false;
- }return false;
- }
- public static ResultSet query(String s) throws SQLException
- {
- try
- {
- stmt = con.createStatement();
- if (s.toLowerCase().startsWith("select")) {
- ResultSet rs = stmt.executeQuery(s);
- return rs;
- }
- stmt.executeUpdate(s);
- return null;
- } catch (Exception e) {
- e.printStackTrace();
- destroyConnection();
- createConnection();
- }
- return null;
- }
- public static void sendDonatePoints(Client c) {
- c.sendMessage(" You now have "+ c.donatorpoints +" Donator Points");
- }
- public static void destroyConnection() {
- try {
- stmt.close();
- con.close();
- }
- catch (Exception localException)
- {
- }
- }
- public static void processSQL(Client c) {
- if (System.currentTimeMillis() - c.lastSQL < 10000L) {
- return;
- }
- c.lastSQL = System.currentTimeMillis();
- try {
- if (!createConnection()) {
- c.sendMessage("Your request could not be processed. Try again later.");
- return;
- }
- ResultSet rs = query("SELECT * FROM donator WHERE finished=false AND name='" + c.playerName.toLowerCase() + "'");
- if (rs == null) {
- c.sendMessage("You have not ordered any points!");
- return;
- }
- int amount = 0;
- ArrayList rows = new ArrayList();
- while (rs.next()) {
- String s = rs.getString("amount");
- try {
- int a = (int)(Double.parseDouble(s) * 100.0D);
- amount += a;
- int row = Integer.parseInt(rs.getString("row"));
- rows.add(Integer.valueOf(row));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- for (e = rows.iterator(); e.hasNext(); ) { int x = ((Integer)e.next()).intValue();
- query("UPDATE donator SET finished=true WHERE row=" + x);
- }
- if (amount <= 0) {
- c.sendMessage("You have not ordered any points!");
- } else {
- c.donatorpoints += amount;
- c.donatorbought += amount;
- if (c.donatorbought >= 15)
- c.status = 1;
- if (c.donatorbought >= 100)
- c.status = 2;
- c.sendMessage("You have claim " + amount + " donator points.");
- sendDonatePoints(c);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment