Advertisement
Guest User

Untitled

a guest
Jul 24th, 2012
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 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.  
  28. String give = "SELECT `given` FROM `has_voted` WHERE `ip` LIKE '+thisIp.getHostAddress()'";
  29. given = st.executeQuery(give);
  30.  
  31. while (given.next()) {
  32. if (given.getInt("given") > 0) {
  33. System.out.println("You've already recieved a reward for the last time you voted, but thanks again for voting.");
  34. } else {
  35. System.out.println("Thanks for voting! You've been rewarded 25m gold! Vote again tomorrow!");
  36. String sql = "SELECT has_voted (given) Replace('0', '0', '1')";
  37. int rows = st.executeUpdate("UPDATE has_voted SET given = 1 WHERE given = 0");
  38. System.out.println("Given reward column set to 1 for the ip address:");//+thisIp.getHostAddress()*
  39. }
  40. }
  41. } catch (Exception e) {
  42. System.out.println(e);
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement