Advertisement
Guest User

Untitled

a guest
Jul 24th, 2012
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class TestConnection {
  4.  
  5. public static void main(String args[]) {
  6.  
  7. Connection con = null;
  8. Statement st = null;
  9. ResultSet auth = null;
  10. ResultSet given = null;
  11.  
  12. String url = "jdbc:mysql://localhost:3306/";
  13. String db = "vote4gold";
  14. String driver = "com.mysql.jdbc.Driver";
  15. String user = "root";
  16. String pass = "";
  17.  
  18. try {
  19. Class.forName(driver);
  20. con = DriverManager.getConnection(url + db, user, pass);
  21. con.setAutoCommit(false);
  22. st = con.createStatement();
  23.  
  24. String give = "SELECT `given` FROM `has_voted` WHERE `ip` LIKE 'hello'";
  25. given = st.executeQuery(give);
  26.  
  27. //if given equals 0 I want it to print "Thanks for voting."
  28. //if given equals 1 I want it to say "Thanks again for voting."
  29.  
  30. System.out.println("Given Reward(0=no 1=yes)"); //in the future this won't matter I just use it for testing purposes as of the moment
  31. while (given.next()) {
  32. System.out.println(given.getString("given"));
  33. }
  34. } catch (Exception e) {
  35. System.out.println(e);
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement