Hi there, I'm not sure which part you wanted me to elaborate on? Suppose you ran an SQL query that retrieved row that had two columns,
colA and
ColB. You'd then create a Java Bean that abstracts this:
package packagename;
class TwoColBean
{
String a, b;
public TwoColBean(String a, String b)
{
this.a = a;
this.b = b;
}
public getA()
{
return a;
}
...
}
So the Bean class would just encapsulate the data of those two columns (assuming they were
String objects) thus a since Bean stores a single row (since each row consists of two columns). You can use a Java Bean (just like any class) by using the JSP tag:
<jsp:useBean id = "dataBean" scope = "request" class = "packagename.TwoColBean" />
You should look up that if you're unfamiliar with the tag. Of course you'd only do this if you wanted to store data into your database using the bean. To output the data, you'd simply import the class:
<%@ page import = "packagename.TwoColBean" %>
Next you'd query the database (probably from another Bean that's responsible for process database requests) and process each row of the ResultSet and store the values into a
List of TwoColBean:
public List getData() throws SQLException
{
List dataList = new ArrayList(); // create empty list
// query database > getDAtaQuery is a PreparedStatment object
ResultSet results = getDataQuery.executeQuery();
// get rows from result and create a TwoColBean and add to list
while ( results.next() ) {
TwoColBean d = new TwoColBean();
d.setId(results.getString( 1 ));
d.setTimestamp(results.getString( 2 ));
dataList.add(d);
}
// return list of "QuotationBeans" to calling jsp page
return quotationList;
}
So in your JSP you'd query your database (using a proper mechanism like a Bean) using the above method call and you'd get your list. Then to display the list:
List quoteList = databaseBean.getData();
Iterator dListIterator = dList.iterator();
TwoColBean d;
while ( dListIterator.hasNext() ) {
d = ( TwoColBean) dListIterator.next();
%> <%-- end scriptlet; insert fixed template data --%>
<tr>
<td><%= d.getColA() %></td>
<td><%= d.getColB() %></td>
</tr>
<% // continue scriptlet
} // end while
%> <%-- end scriptlet --%>
Hope this makes sense and helps.