I have got a jsp page which has 5 columns and 12 rows .I have to retrieve data in such a way that the first record fetched should go in to first row,,,,the second in second row.....How can I do it?
Asked
Active
Viewed 1,701 times
3 Answers
1
connect to DB in servlet fetch the data using JDBC
and set required data to request/session/application scope as needed and forward the request to view (jsp)
Also See
0
Completely agree with the above - in any serious production application database should happen in Java/JDBC in a proper controller, and not in the view (JSP).
But, sometimes it makes sense to use JSTL's SQL capabilities, check out a good JSTL primer here: http://www.ibm.com/developerworks/java/library/j-jstl0520/index.html
Some relevant code:
<sql:setDataSource var="dataSrc"
url="jdbc:mysql:///taglib" driver="org.gjt.mm.mysql.Driver"
user="admin" password="secret"/>
<sql:query var="queryResults" dataSource="${dataSrc}">
select * from blog group by created desc limit ?
<sql:param value="${6}"/></sql:query>
<table border="1">
<tr>
<th>ID</th>
<th>Created</th>
<th>Title</th>
<th>Author</th>
</tr>
<c:forEach var="row" items="${queryResults.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.created}"/></td>
<td><c:out value="${row.title}"/></td>
<td><c:out value="${row.author}"/></td>
</tr>
</c:forEach>
</table>

Shay Rojansky
- 15,357
- 2
- 40
- 69