List<CommonDTO> subjectList = new ArrayList<CommonDTO>();
try {
pstmt = conn.prepareStatement(SLCMQueryConstant.SEARCH_SUBJECT);
pstmt.setString(1, commonDTO.getSubjectName());
pstmt.setString(2, commonDTO.getSubjectCode());
if(commonDTO.getIsActive()==0){
pstmt.setInt(3, commonDTO.IsActive = 1);
}
else{
pstmt.setInt(3, commonDTO.IsActive= 0);
}
rs = pstmt.executeQuery();
int count = 0;
while (rs.next()) {
count++;
CommonDTO commondto = new CommonDTO();
commondto.setSubjectId(rs.getInt("Subject_Id"));
commondto.setSubjectCode(rs.getString("Subject_Code"));
commondto.setSubjectName(rs.getString("SubjectName"));
commondto.setSubjectNameHindi(rs.getString("SubjectName_Hindi"));
commondto.setIsActive(rs.getInt("Is_Active"));
commondto.setViewcount(count);
subjectList.add(commondto);
}
System.out.println(count);
}
return subjectList;
public static final String SEARCH_SUBJECT = new StringBuilder("").
append(" SELECT Subject_Id,Subject_Code,SubjectName,SubjectName_Hindi,Is_Active").
append(" FROM M_Subject_Master WHERE Subject_Id=IFNULL(NULL,Subject_Id) ").
append(" AND (SubjectName IS NULL OR SubjectName LIKE CONCAT('%',?,'%'))").
append(" AND (Subject_Code IS NULL OR Subject_Code LIKE CONCAT('%',?,'%'))").
append(" AND Is_Active = ? ").
append(" ORDER BY SubjectName").toString();
JSP Page顯示記錄數 ==================================== =====如何統計從數據庫找到的記錄數,並使用struts2在jsp頁面中顯示?
<s:iterator value="subjectList" var="quesvar" status="questat">
<s:hidden value="%{subjectId}" name="commonDTO.subjectId" id="subjectId"></s:hidden>
<td valign="top" class="style11" style="width: 20%;text-align:left">No.Of Records Found<s:property value="subjectList[#questat.index].viewcount"/></td>
<tr class="item">
<td valign="top" class="style10" style="width: 10%;text-align:left"><s:property value="#questat.count"/></td>
<td valign="top" class="style11" style="width: 20%;text-align:left"><s:property value="subjectList[#questat.index].subjectCode"/></td>
<td valign="top" class="style11" style="width: 20%;text-align:left"><s:property value="subjectList[#questat.index].subjectName"/> </td>
<td valign="top" class="style11" style="width: 20%;"><a href="#" onClick="editSubject(<s:property value="subjectList[#questat.index].subjectId"/>)" >View/Edit</a>
</tr>
</s:iterator>
我該如何統計數據庫中的記錄數量並在jsp頁面上打印? 我不使用另一個準備語句計數如何顯示從數據庫中獲取jsp記錄的數量。
thanx它工作正常 – pink
@pink偉大,你能否驗證答案,以便其他人可以在未來使用它?謝謝! – cralfaro