Skip to content

Instantly share code, notes, and snippets.

@dusanstanojeviccs
Last active December 25, 2017 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dusanstanojeviccs/d23863bde0077b92e4b62579d111b551 to your computer and use it in GitHub Desktop.
Save dusanstanojeviccs/d23863bde0077b92e4b62579d111b551 to your computer and use it in GitHub Desktop.
public List<Book> findAll() throws SQLException {
PreparedStatement preparedStatement = database.getConnection().prepareStatement("select * from books");
List<Book> books = new ArrayList<>();
preparedStatement.execute();
ResultSet rs = preparedStatement.getResultSet();
while (rs.next()) {
Book book = new Book();
book.setId(rs.getInt("id"));
book.setTitle(rs.getString("title"));
book.setDescription(rs.getString("description"));
books.add(book);
}
return books;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment