i am doing a program on selecting suitable link to user, by first accepting their input, such as main ingredient, cooking method , and allergies. i use database report (using database palette), and success generate the result. the problem is, if there is no result for that sql statement, i want to return error message. how do i do that using database report?
i'm using netbeans, glassfish, and mysql database.
here is my code:
<sql:query var="result" dataSource="jdbc/foodSys">
SELECT distinct Link FROM filtered
where maining = '<%=request.getParameter("cate_1")%>'
and cookmet='<%=request.getParameter("cate_2")%>'
and allergies='<%=request.getParameter("cate_5")%>'
</sql:query>
<table border="1">
<tr>
<c:forEach var="columnName" items="${result.columnNames}">
<th><c:out value="${columnName}"/></th>
</c:forEach>
</tr>
<c:forEach var="row" items="${result.rowsByIndex}">
<tr>
<c:forEach var="column" items="${row}">
<td><c:out value="${column}"/></td>
</c:forEach>
</tr>
</c:forEach>
</table>
Try choose
when
otherwise
tags, and check for empty result.rows
<c:choose>
<c:when test="${empty result.rows}">
<p>Error Message</p>
</c:when>
<c:otherwise>
<table border="1">
<tr>
<c:forEach var="columnName" items="${result.columnNames}">
<th><c:out value="${columnName}"/></th>
</c:forEach>
</tr>
<c:forEach var="row" items="${result.rowsByIndex}">
<tr>
<c:forEach var="column" items="${row}">
<td><c:out value="${column}"/></td>
</c:forEach>
</tr>
</c:forEach>
</table>
</c:otherwise>
</c:choose>