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?

1

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

1

Start from Basic JSP Sample : Database Access - JDBC.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.