Usually when I do JSP/Servlet and use persistence through a database I have a DAO for each table more or less as well as a sort of manager that uses the DAO to access the database. The manager it self will be the one with the logic before inserts and after selects so to speak.
For instance a way of doing your thing could be to have a CustomerManager, ItemManager etc.
public class CustomerManager {
public List<CustomerBean> search(final String search) {
// TODO: Create the logic that calls off to the DAO and gets the search results back.
// For example this could be a simple query such as
// "SELECT customerid,customername FROM customers WHERE customername LIKE '%?%'"
// where the ? represents the search string. Just make sure you escape it or use the
// correct tools for accessing the database.
// Of course you can compliment this method by taking another argument for what field in the table you
// wish to perform the search on, for instance you might want to search for a customer by id.
}
public List<CustomerBean> getCustomers() {
// This is a method that returns ALL customers from the database
}
public CustomerBean getCustomer(final int customerId) {
// Select the customer with a specific customer id and return that customer.
}
}
You will of course need other methods as well, such as add and delete customer and maybe also a setCustomer method for changing the data of a customer.
I hope this helps somewhat.
For another approach which might be somewhat over course, I've implemented another search on my sites lately were I use
Apache Lucene - Overview to index and search for my products.
Whenever I add or remove a product from my database I add/remove an index record using Lucene. When a user then searches for a product I just return some of the indexed data which matches the search criteria. Then I print out a list of these products and thats it. When you click one of the links it actually selects the product from the database and displays the product page.
// Json