Java Reference
In-Depth Information
Listing 1-7. BookDAO Interface
1. package com.apress.books.dao;
2.
3. import java.util.List;
4.
5. import com.apress.books.model.Book;
6. import com.apress.books.model.Category;
7.
8. public interface BookDAO {
9. public List<Book>findAllBooks();
10.
11. public List<Book>searchBooksByKeyword(String keyWord);
12.
13. public List<Category>findAllCategories();
14.
15. public void insert(Book book);
16.
17. public void update(Book book);
18.
19. public void delete(Long bookId);
20.
21. }
Line 9 : This is the findAllBooks() method for listing all the topics from the
database.
Line 11 : SearchBooksByKeyword(String keyWord) allows the user to search
books by keyword in the title of the topic or by the first and last names of the
author.
Line 13 : findAllCategories() is required by the application to provide a
categorized listing of books.
The methods in this interface correspond to the CRUD terms (in other words, create, read, update,
and delete) of the application. Listing 1-8 illustrates the implementation of the BookDAO interface.
Listing 1-8. Implementation of the BookDAO Interface
1. package com.apress.books.dao;
2.
3. import java.sql.Connection;
4. import java.sql.DriverManager;
5. import java.sql.PreparedStatement;
6. import java.sql.ResultSet;
7. import java.sql.SQLException;
8. import java.sql.Statement;
9. import java.util.ArrayList;
10. import java.util.List;
11.
12. import java.apress.books.model.Author;
13. import java.apress.books.model.Book;
Search WWH ::




Custom Search