0

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?

RAS
  • 7,965
  • 16
  • 63
  • 84
PROXY
  • 599
  • 1
  • 4
  • 4
  • 1
    possible duplicate of [Displaying database result in JSP](http://stackoverflow.com/questions/4196197/displaying-database-result-in-jsp) – BalusC Mar 01 '11 at 12:36

3 Answers3

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

Community
  • 1
  • 1
jmj
  • 232,312
  • 42
  • 391
  • 431
1

Start from Basic JSP Sample : Database Access - JDBC.

zengr
  • 37,540
  • 37
  • 125
  • 190
asgs
  • 3,828
  • 6
  • 39
  • 53
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
  • 13,273
  • 2
  • 33
  • 53