Advertisement
Guest User

Untitled

a guest
Jul 24th, 2012
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. import java.sql.*;
  2. import java.net.*;
  3. import java.io.*;
  4. import java.util.*;
  5. import java.lang.*;
  6.  
  7. public class TestConnection {
  8.  
  9. public static void main(String args[]) {
  10.  
  11. Connection con = null;
  12. Statement st = null;
  13. ResultSet auth = null;
  14. ResultSet given = null;
  15.  
  16. String url = "jdbc:mysql://localhost:3306/";
  17. String db = "vote4gold";
  18. String driver = "com.mysql.jdbc.Driver";
  19. String user = "root";
  20. String pass = "";
  21.  
  22. try {
  23. Class.forName(driver);
  24. con = DriverManager.getConnection(url + db, user, pass);
  25. con.setAutoCommit(false);
  26. st = con.createStatement();
  27. InetAddress thisIp =InetAddress.getLocalHost();
  28. System.out.println("IP:"+thisIp.getHostAddress());
  29.  
  30. //String give = "SELECT `given` FROM `has_voted` WHERE `ip` LIKE '+thisIp.getHostAddress()'";
  31. String give = "SELECT `given` FROM `has_voted` " +
  32. "WHERE `ip` LIKE '" + thisIp.getHostAddress() + "'";
  33. given = st.executeQuery(give);
  34.  
  35. while (given.next()) {
  36. if (given.getInt("given") > 0) {
  37. System.out.println("You've already recieved a reward for the last time you voted, but thanks again for voting.");
  38. } else {
  39. System.out.println("Thanks for voting! You've been rewarded 25m gold! Vote again tomorrow!");
  40. String sql = "SELECT has_voted (given) Replace('0', '0', '1')";
  41. int rows = st.executeUpdate("UPDATE has_voted SET given = 1 WHERE given = 0");
  42. System.out.println("Given reward column set to 1 for the ip address:");//+thisIp.getHostAddress()
  43. }
  44. }
  45. } catch (Exception e) {
  46. System.out.println(e);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement