CHAPTER 1: Introducing Java Web Development 33 Lines 30 to 37: The connections need to be closed because connections are
expensive when it comes to the performance of the application.
Lines 39 to 144: These lines are implementations of CRUD services in the
BookDAO interface.
Lines 67, 108, and 133: You created a connection for each statement in the
CRUD services. You need to close these connections; keeping them open will
result in the poor performance of the application.Client for the Data Access Layer
Now that your data access layer is ready, you will query it with a stand-alone Java application. In
Chapter 2, you will replace this Java app with a web application. Listing 1-9 illustrates the Java
application.
Listing 1-9. Stand-Alone Bookstore Java App
- package com.apress.books.client;
- import java.util.List;
- import com.apress.books.dao.BookDAO;
- import com.apress.books.dao.BookDAOImpl;
- import com.apress.books.model.Book;
- public class BookApp {
- private static BookDAO bookDao = new BookDAOImpl();
- public static void main(String[] args) {
- // List all books
- System.err.println("Listing all Books:");
- findAllBooks();
- System.out.println();
- // search book by keyword
- System.err.println("Search book by keyword in book title : Groovy:");
- searchBooks("Groovy");
- System.out.println();
- System.err.println("Search book by keyword in author's name : Josh:");
- searchBooks("Josh");
- }
- private static void findAllBooks() {
- List
books = bookDao.findAllBooks(); - for (Book book : books) {
- System.out.println(book);
- }
- }
- private static void searchBooks(String keyWord) {