Java Reference
In-Depth Information
+ ") or"
+ " (parent = "
+ getParent()
+ ") order by number";
In this query, we'll retrieve the top-level thread and the replies. To do so, we'll
retrieve a row from the database if the number of the specified top-level
thread, called parent, is equal to the number of the primary post ( number =
getParent() ) or the parent ( parent = getParent () ). This is how we repre-
sent a top-level discussion, or thread:
Statement statement = connection.createStatement();
result = statement.executeQuery(query);
while (result.next()) {
subject.addElement(result.getString(SUBJECT_COLUMN));
author.addElement(result.getString(AUTHOR_COLUMN));
board.addElement(result.getString(BOARD_COLUMN));
postText.addElement(result.getString(POSTTEXT_COLUMN));
}
result.close();
statement.close();
connection.close();
}
}
We then execute the query. Next, we populate our attributes with a pass
through the result sets. Finally, we clean up.
The controller for ShowThread
Our ShowThreadController is nearly identical to ShowBoardController . To
save space, once again, we'll show only the interesting performTask method:
public void performTask(
HttpServletRequest request,
HttpServletResponse response) {
try {
String parent=request.getParameter ("parent");
ShowThreadCommand fullThread = new ShowThreadCommand();
fullThread.setParent(parent);
fullThread.initialize();
fullThread.execute();
In this case, we're showing all of the posts related to a thread. We want to set
the top-level parent, which is passed into this method as a URL parameter. We
then use our established protocol of create , set , initialize , and execute :
request.setAttribute("ShowThreadCommand", fullThread);
ServletContext servletContext = getServletContext ();
Search WWH ::




Custom Search