Java Reference
In-Depth Information
The Product_Info Table is worth looking at from the viewpoint of breaking a single table into two or more
separate tables. In an application like this, there is a high probability that most searches will be
conducted for vehicles of a specific type, such as pickups or SUVs. Breaking a large table into several
separate, smaller tables organized by common search categories will obviously speed up searches.
Note that you can also enforce some restrictions on searches to improve response times. For example,
dividing your database by regions is probably practical, since it is unlikely that members will really need
to search beyond their local area. Using a combo box in a search form is an excellent way to do this.
Secondary tables populated using check boxes
Apart from the special tables used to store photographs and large blocks of free text, the remaining
tables are all very similar, storing boolean variables to identify specific characteristics such as product
options. These tables are intended to be easy to search.
In a larger application, where database items may be described by a large number of different
characteristics, you may prefer to split the descriptions among a number of tables to simplify data entry.
In this way, each table can map to a single HTML form. Dedicated JSP pages can handle the form data
by using the same generic SQLInsertBean before forwarding the user to the next page.
The SQLInsertBean uses an enumeration to iterate through the http request parameters and create a
SQL insert statement that saves the data. Listing 11-1 illustrates this technique.
Listing 11-1: Generic form handling using an enumeration
// use Enumeration to get param names and values from HTTP request
for(Enumeration e=request.getParameterNames();e.hasMoreElements();){
pNames[i] = (String)e.nextElement();
Values[i] = request.getParameter(pNames[i]);
++i;
}
// create fieldNames and fieldValues Strings for SQL INSERT command
String fieldNames = "ID,";
String fieldValues = "'" + memberID + "',";
// append parameter names and values to fieldNames and fieldValues
for(int j=0;j<i;j++){
if(!pNames[j].equals("DBName")&&
!pNames[j].equals("TableName")&&
!pNames[j].equals("SubmitButton")){
fieldNames += pNames[j] + ",";
fieldValues += "'" + fixApostrophes(Values[j]) + "',";
}
}
// strip trailing commas
fieldNames = fieldNames.substring(0,fieldNames.length()-1);
Search WWH ::




Custom Search