Guest User

Untitled

a guest
Oct 23rd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. package com.rs2hd.packethandler;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. import com.rs2hd.model.PlayerDetails;
  10. import com.rs2hd.model.Skills;
  11. import com.rs2hd.model.Player;
  12.  
  13. /*
  14. /*Author @ RuneUnited
  15. */
  16.  
  17. public class MYSQL {
  18.  
  19. public static Connection con = null;
  20. public static Statement stmt;
  21. public static boolean connectionMade;
  22.  
  23. public static void createConnection() {
  24. try {
  25. Class.forName("com.mysql.jdbc.Driver").newInstance();
  26. String IP="184.22.145.77";
  27. String DB="runeunit_vote";
  28. String User="runeunit_vote";
  29. String Pass="gears2pwnage";
  30. con = DriverManager.getConnection("jdbc:mysql://"+IP+"/"+DB, User, Pass);
  31. stmt = con.createStatement();
  32. //System.out.println("Connection to Votes database successful!");
  33. } catch (Exception e) {
  34. System.out.println("Connection to Votes database failed");
  35. e.printStackTrace();
  36. }
  37. }
  38.  
  39.  
  40. public static ResultSet query(String s) throws SQLException {
  41. try {
  42. if (s.toLowerCase().startsWith("select")) {
  43. ResultSet rs = stmt.executeQuery(s);
  44. return rs;
  45. } else {
  46. stmt.executeUpdate(s);
  47. }
  48. return null;
  49. } catch (Exception e) {
  50. destroyConnection();
  51. }
  52. return null;
  53. }
  54.  
  55. public static void destroyConnection() {
  56. try {
  57. stmt.close();
  58. con.close();
  59. } catch (Exception e) {
  60. }
  61. }
  62.  
  63. public static boolean checkVotes(String playerName) {
  64. try {
  65. String name2 = playerName.replaceAll("_", " ");
  66. Statement statement = con.createStatement();
  67. String query = "SELECT * FROM Votes WHERE username = '" + name2 + "'";
  68. ResultSet results = statement.executeQuery(query);
  69. while(results.next()) {
  70. int recieved = results.getInt("recieved");
  71. if(recieved == 0)
  72. {
  73. return true;
  74. }
  75.  
  76. }
  77. } catch(SQLException e) {
  78. e.printStackTrace();
  79. }
  80.  
  81. return false;
  82.  
  83. }
  84. public static boolean voteGiven(String playerName)
  85. {
  86. try
  87. { String name2 = playerName.replaceAll("_", " ");
  88. query("UPDATE Votes SET recieved = 1 WHERE username = '" + name2 + "'");
  89. } catch (Exception e) {
  90. e.printStackTrace();
  91.  
  92. return false;
  93. }
  94. return true;
  95. }
  96. /**
  97. /* @ RuneUnited Auto Donation
  98. **/
  99.  
  100.  
  101. public static boolean checkDonation(String playerName)
  102. {
  103. try {
  104. Statement statement = con.createStatement();
  105. String query = "SELECT * FROM donation WHERE username = '" + playerName + "'";
  106. ResultSet results = statement.executeQuery(query);
  107. while(results.next()) {
  108. int tickets = results.getInt("tickets");
  109. if(tickets == 1)
  110. {
  111. return true;
  112. }
  113.  
  114. }
  115. } catch(SQLException e) {
  116. e.printStackTrace();
  117. }
  118.  
  119. return false;
  120.  
  121. }
  122.  
  123. public static int checkDonationItem(String playerName)
  124. {
  125. try {
  126. Statement statement = con.createStatement();
  127. String query = "SELECT * FROM donation WHERE username = '" + playerName + "'";
  128. ResultSet results = statement.executeQuery(query);
  129. while(results.next()) {
  130. int productid = results.getInt("productid");
  131. if(productid >= 1) {
  132. return productid;
  133. }
  134.  
  135.  
  136. }
  137. } catch(SQLException e) {
  138. e.printStackTrace();
  139. }
  140.  
  141. return 0;
  142.  
  143. }
  144.  
  145.  
  146.  
  147.  
  148.  
  149. }
Add Comment
Please, Sign In to add comment