Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public List<String> getCategories() {
  2.  
  3. // 2. Create an empty ArrayList of <String> for the categories
  4. List<String> ret = new ArrayList<>();
  5.  
  6. final String sql = "SELECT name FROM Music_Categories order by name asc";
  7. try (
  8. Connection myConn = DriverManager.getConnection(
  9. "jdbc:mysql://localhost:3306/rainforestdb", "student", "student");
  10. Statement myStmt = myConn.createStatement();
  11. ResultSet rs = myStmt.executeQuery(sql);
  12. ){
  13.  
  14. // 4. Process result and place data in the categories ArrayList
  15. while (rs.next()) {
  16. ret.add(rs.getString(1));
  17. }
  18. }
  19. catch (SQLException exc) {
  20. logger.severe(exc.toString());
  21. }
  22.  
  23. // 5. Return the categories ArrayList
  24. return ret;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement