Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<String> getCategories() {
- // 2. Create an empty ArrayList of <String> for the categories
- List<String> ret = new ArrayList<>();
- final String sql = "SELECT name FROM Music_Categories order by name asc";
- try (
- Connection myConn = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/rainforestdb", "student", "student");
- Statement myStmt = myConn.createStatement();
- ResultSet rs = myStmt.executeQuery(sql);
- ){
- // 4. Process result and place data in the categories ArrayList
- while (rs.next()) {
- ret.add(rs.getString(1));
- }
- }
- catch (SQLException exc) {
- logger.severe(exc.toString());
- }
- // 5. Return the categories ArrayList
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement