Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import java.util.*;
  2. import java.sql.*;
  3.  
  4.  
  5. public class FanData
  6. {
  7. public static void main(String args[])
  8. {
  9. ArrayList<Fan> fans = new ArrayList<Fan>();
  10.  
  11.  
  12. try
  13. {
  14. //database connection
  15. Class.forName("com.mysql.jdbc.Driver");
  16. Connection conn = DriverManager.getConnection(
  17. "jdbc:mysql://localhost:3306/f9n", "root", "");
  18.  
  19. Statement stat = conn.createStatement();
  20. ResultSet results = stat.executeQuery("select * from fans");
  21.  
  22. while(results.next())
  23. {
  24. Fan fan =
  25. new Fan((Integer)(results.getObject(1)),
  26. results.getString(2),
  27. results.getString(3),
  28. results.getString(4));
  29.  
  30. fans.add(fan);
  31. }
  32.  
  33. conn.close();
  34.  
  35. for(Fan f:fans)
  36. {
  37. System.out.println(f);
  38. }
  39. }
  40. catch(Exception e)
  41. {
  42. e.printStackTrace();
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement