Advertisement
Guest User

Untitled

a guest
May 21st, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import java.sql.*;
  2. import java.security.MessageDigest;
  3.  
  4. public class SQL {
  5.  
  6. public static Connection con = null;
  7. public static Statement stm;
  8.  
  9. public static void createConnection() {
  10. try {
  11. Class.forName("com.mysql.jdbc.Driver").newInstance();
  12. con = DriverManager.getConnection("jdbc:mysql://wsevolutions.com/wsevo_server", "wsevo_wsforum", "10022388");
  13. stm = con.createStatement();
  14. } catch (Exception e) {
  15. e.printStackTrace();
  16. }
  17. }
  18. public void run() {
  19. while(true) {
  20. try {
  21. createConnection();
  22. misc.println("Connected to the MYSQL database");
  23. } catch (Exception e) {
  24. e.printStackTrace();
  25. }
  26. }
  27. }
  28. public static ResultSet query(String s) throws SQLException {
  29. try {
  30. if (s.toLowerCase().startsWith("select")) {
  31. ResultSet rs = stm.executeQuery(s);
  32. return rs;
  33. } else {
  34. stm.executeUpdate(s);
  35. }
  36. return null;
  37. } catch (Exception e) {
  38. misc.println("MySQL Error:"+s);
  39. e.printStackTrace();
  40. }
  41. return null;
  42. }
  43.  
  44. public static void destroyCon() {
  45. try {
  46. stm.close();
  47. con.close();
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. }
  51. }
  52.  
  53. public static boolean checkVotes(String playerName)
  54. {
  55. try {
  56. Statement statement = con.createStatement();
  57. String query = "SELECT * FROM Votes WHERE username = '" + playerName + "'";
  58. ResultSet results = statement.executeQuery(query);
  59. while(results.next()) {
  60. int recieved = results.getInt("recieved");
  61. if(recieved == 0)
  62. {
  63. return true;
  64. }
  65.  
  66. }
  67. } catch(SQLException e) {
  68. e.printStackTrace();
  69. }
  70. return false;
  71. }
  72. public static boolean voteGiven(String playerName)
  73. {
  74. try
  75. {
  76. query("UPDATE Votes SET recieved = 1 WHERE username = '" + playerName + "'");
  77. } catch (Exception e) {
  78. e.printStackTrace();
  79. return false;
  80. }
  81. return true;
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement