Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package server.util;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class SQL {
- public static Connection con = null;
- public static Statement stmt;
- public static boolean printed = false;
- public static boolean createConnection() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- con = DriverManager.getConnection(
- "jdbc:mysql://box332.bluehost.com:3306/impactpk_imp", "impactpk_hs", "terr");
- stmt = con.createStatement();
- return true;
- } catch (Exception e) {
- return false;
- }
- //return false;
- }
- public static boolean createConnection2() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- con = DriverManager.getConnection(
- "jdbc:mysql://localhost/highscores", "root", "roflcakes");
- stmt = con.createStatement();
- return true;
- } catch (Exception e) {
- if(!printed) {
- e.printStackTrace();
- printed = true;
- }
- return false;
- }
- //return false;
- }
- public static ResultSet query(String s) throws SQLException {
- try {
- if (s.toLowerCase().startsWith("select")) {
- ResultSet rs = stmt.executeQuery(s);
- return rs;
- } else {
- stmt.executeUpdate(s);
- }
- return null;
- } catch (Exception e) {
- e.printStackTrace();
- destroyConnection();
- createConnection();
- }
- return null;
- }
- public static void destroyConnection() {
- try {
- stmt.close();
- con.close();
- } catch (Exception e) {
- }
- }
- }
- /*OHAIDERRRRRRRRRRRRRRRR*/
- public static void processSQL(Client c) {
- try {
- if(!SQL.createConnection()) {
- c.sendMessage("Your request could not be processed. Try again later.");
- return;
- }
- ResultSet rs = SQL.query("SELECT * FROM donator WHERE finished=false AND name='" + c.playerName + "'");
- if(rs == null) {
- c.sendMessage("You have not ordered any points!");
- return;
- }
- int amount = 0;
- ArrayList<Integer> rows = new ArrayList<Integer>();
- while (rs.next()) {
- String s = rs.getString("amount");
- try {
- int a = (int)(Double.parseDouble(s) * 100);
- amount += a;
- int row = Integer.parseInt(rs.getString("row"));
- rows.add(row);
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- for(int x : rows) {
- SQL.query("UPDATE donator SET finished=true WHERE row=" + x);
- }
- if(amount <= 0) {
- c.sendMessage("You have not ordered any points!");
- } else {
- c.donatePoints += amount;
- c.sendMessage("You have been given " + amount + " donator points.");
- }
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- /*MORE OHAIDERRRRRRRRRRRR*/
- if (playerCommand.toLowerCase().startsWith("getpoints")) {
- EventManager.processSQL(c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement