Advertisement
Guest User

getgenre

a guest
Feb 15th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package bigdatamangementcs1;
  7.  
  8. /**
  9. *
  10. * @author cyl1
  11. */
  12. import java.sql.*;
  13.  
  14. public class getgenres {
  15.  
  16. /**
  17. * @param args the command line arguments
  18. */
  19. public static void main(String[] args) {
  20. try {
  21. Class.forName("com.mysql.jdbc.Driver").newInstance();
  22. Connection conn = DriverManager.getConnection("jdbc:mysql://mysql-server-1.macs.hw.ac.uk/movielens?user=cyl1&password=abccyl1354");
  23. Statement st = conn.createStatement();
  24. String query = "SELECT * FROM genres";
  25. ResultSet rs = st.executeQuery(query);
  26. System.out.println("testing");
  27. while(rs.next()){
  28. int id = rs.getInt("id");
  29. String genre = rs.getString("genre");
  30. System.out.format("%s %s\n", id,genre);
  31. }
  32. st.close();
  33. conn.close();
  34. } catch (Exception e) {
  35. System.out.println("ERROR!! " +e);
  36. }
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement