Advertisement
Guest User

Untitled

a guest
Sep 29th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. package com.rs2hd;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.sql.*;
  8. import java.security.MessageDigest;
  9.  
  10. import com.rs2hd.model.Player;
  11.  
  12. /**
  13. * MySQL Class
  14. * @author Ryan / Lmctruck30, Cleaned and edited by @RuneUnited
  15. *
  16. */
  17.  
  18. public class MysqlManager {
  19.  
  20. public static Connection conn = null;
  21. public static Statement statement = null;
  22. public static ResultSet results = null;
  23.  
  24. public static String MySQLDataBase = "smf";
  25. public static String MySQLURL = "localhost:3306";
  26. public static String MySQLUser = "root";
  27. public static String MySQLPassword = "lovesparc";
  28.  
  29. public synchronized static void createConnection() {
  30. try {
  31. Class.forName("com.mysql.jdbc.Driver").newInstance();
  32. conn = DriverManager.getConnection("jdbc:mysql://"+MySQLURL+"/"+MySQLDataBase, MySQLUser, MySQLPassword);
  33. statement = conn.createStatement();
  34. //Misc.println("Connection to Vote database successful!");
  35. } catch (Exception e) {
  36. //Misc.println("Connection to Donation database failed");
  37. e.printStackTrace();
  38. }
  39. }
  40.  
  41. public synchronized static void destroyConnection() {
  42. try {
  43. statement.close();
  44. conn.close();
  45. System.out.println("MySQL did not connect");
  46. } catch (Exception e) {
  47. //e.printStackTrace();
  48. }
  49. }
  50.  
  51. public synchronized static ResultSet query(String s) throws SQLException {
  52. try {
  53. if (s.toLowerCase().startsWith("select")) {
  54. ResultSet rs = statement.executeQuery(s);
  55. return rs;
  56. } else {
  57. statement.executeUpdate(s);
  58. }
  59. return null;
  60. } catch (Exception e) {
  61. destroyConnection();
  62. createConnection();
  63. //e.printStackTrace();
  64. }
  65. return null;
  66. }
  67.  
  68. public static void checkVote(Player p) {
  69. try {
  70. createConnection();
  71. Statement stmt = conn.createStatement();
  72. ResultSet rs = stmt
  73. .executeQuery("SELECT COUNT(playerName) AS total FROM `votes` WHERE `playerName`= \""
  74. + p.getDisplayName() + "\" AND `recieved`= 0");
  75. rs.first();
  76. int total = rs.getInt("total");
  77. if (total == 1) {
  78. stmt.execute("UPDATE `votes` SET `recieved` = 1 WHERE `playerName` = '" + p.getDisplayName() + "'");
  79. p.getInventory().addItem(995, 10000000);
  80. p.getActionSender().sendMessage("Thanks for voting!");
  81. }
  82. } catch (SQLException ex) {
  83. System.out.println(ex);
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement