Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rs2hd;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.*;
- import java.security.MessageDigest;
- import com.rs2hd.model.Player;
- /**
- * MySQL Class
- * @author Ryan / Lmctruck30, Cleaned and edited by @RuneUnited
- *
- */
- public class MysqlManager {
- public static Connection conn = null;
- public static Statement statement = null;
- public static ResultSet results = null;
- public static String MySQLDataBase = "smf";
- public static String MySQLURL = "localhost:3306";
- public static String MySQLUser = "root";
- public static String MySQLPassword = "lovesparc";
- public synchronized static void createConnection() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- conn = DriverManager.getConnection("jdbc:mysql://"+MySQLURL+"/"+MySQLDataBase, MySQLUser, MySQLPassword);
- statement = conn.createStatement();
- //Misc.println("Connection to Vote database successful!");
- } catch (Exception e) {
- //Misc.println("Connection to Donation database failed");
- e.printStackTrace();
- }
- }
- public synchronized static void destroyConnection() {
- try {
- statement.close();
- conn.close();
- System.out.println("MySQL did not connect");
- } catch (Exception e) {
- //e.printStackTrace();
- }
- }
- public synchronized static ResultSet query(String s) throws SQLException {
- try {
- if (s.toLowerCase().startsWith("select")) {
- ResultSet rs = statement.executeQuery(s);
- return rs;
- } else {
- statement.executeUpdate(s);
- }
- return null;
- } catch (Exception e) {
- destroyConnection();
- createConnection();
- //e.printStackTrace();
- }
- return null;
- }
- public static void checkVote(Player p) {
- try {
- createConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt
- .executeQuery("SELECT COUNT(playerName) AS total FROM `votes` WHERE `playerName`= \""
- + p.getDisplayName() + "\" AND `recieved`= 0");
- rs.first();
- int total = rs.getInt("total");
- if (total == 1) {
- stmt.execute("UPDATE `votes` SET `recieved` = 1 WHERE `playerName` = '" + p.getDisplayName() + "'");
- p.getInventory().addItem(995, 10000000);
- p.getActionSender().sendMessage("Thanks for voting!");
- }
- } catch (SQLException ex) {
- System.out.println(ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement