I have the following statement in my
servlet that just retrieves three columns from a very simple table (MySQL) where I alias the column names so I can use the column aliases as HTML table headers. The result set is sent to my
jsp file.
--Servlet code snippet
PreparedStatement stmtComm = conn1.prepareStatement("select comment_date 'Comment Date', user 'User', comment 'Comment' from issue_comments where issue_name = (?)");
stmtComm.setString(1,vvalue);
ResultSet rsltComment = stmtComm.executeQuery();
Result resultComment = ResultSupport.toResult(rsltComment);
request.setAttribute("resultComms",resultComment);
The request gets created without any issues, but once I try and view the results, I see the correct aliased column headers in my JSP, but the date field is blank (all other data is displayed). When I don't alias the columns in my query (and use the actual column names) then the date field displays. I can't seem to get the column alias and the date information to print out in the jsp file. Below is my jsp code:
<c:choose>
<c:when test="${resultComms.rowCount ne 0}" >
<table border=1>
<tr>
<c:forEach var="hl" items="${resultComms.columnNames}">
<th><c
ut value="${hl}"/></th>
</c:forEach>
</tr>
<c:forEach var="el" items="${resultComms.rows}">
<tr><TD>
<b><c
ut value="${el.comment_date}"/></b>
</TD><TD>
<c
ut value="${el.user}"/>
</td><td>
<c
ut value="${el.comment}"/>
</td></tr>
</c:forEach>
</table>
</c:when>
<c
therwise>
<center><b>There are no comments recorded for this issue.</b></center>
</c
therwise>
</c:choose>
My theory is that since I aliased my comment_date column to 'Comment Date', then the expression <c
ut value="${el.comment_date}"/> is no longer valid - since the column name returned in the Result object is called 'Comment Date' and not 'comment_date'. Of course, this doesn't explain why the other columns printed out...
Cn anyone provide any resources to help me with this issue?
My bare-bones environment: WinXP, MySQL,
Tomcat 5, Servlet 2.4, JSP 2.0, JSTL 1.1
Thanks in advance,
Scott