Results 1 to 1 of 1
  1. #1
    danpj is offline Member
    Join Date
    Jul 2009
    Posts
    1
    Rep Power
    0

    Default Help in retreiving database data using a loop

    Hi, new here, please help me with my problem.

    In my database table, (SQL) I have 2 coloumns AgtName and Tier1.
    Within this table there are these data

    AgtName Tier1
    a b
    b c
    c d
    d NA
    e b

    My orginal plan was to use JSTL to retreive the data in a loop function. It will search the second coloumn and retreive data in a zigzag style. It would also stop when the data is NA
    An example is when the search paramater is 'a', it would retreive the data like this ' b c d NA'
    If it is 'e', it would be 'b c d NA'

    These are my codes
    <c:choose>
    <c:when test="${param.search!=null}">
    <sql:query var="result2" dataSource="${dataSource}">
    select * from testinzigzag
    where Name like ?
    <sql:param value="${param.search}" />
    </sql:query>
    <c:forEach var="row2" items="${result2.rows}">
    <c:choose>
    <c:when test="${row2.UpperTier!='NA'}">
    ${row2.UpperTier}
    <c:set var="loopVar" value="${row2.UpperTier}" />


    <c:choose>
    <c:when test="${row2.UpperTier!='NA'}">
    <sql:query var="result3" dataSource="${dataSource}">
    select * from testinzigzag
    where Name like ?
    <sql:param value="${row2.UpperTier}" />
    </sql:query>
    <c:forEach var="row3" items="${result3.rows}">
    ${row3.UpperTier}

    <c:choose>
    <c:when test="${row3.UpperTier!='NA'}">
    <sql:query var="result4" dataSource="${dataSource}">
    select * from testinzigzag
    where Name like ?
    <sql:param value="${row3.UpperTier}" />
    </sql:query>
    <c:forEach var="row4" items="${result4.rows}">
    ${row4.UpperTier}

    <c:choose>
    <c:when test="${row4.UpperTier!='NA'}">
    <sql:query var="result5" dataSource="${dataSource}">
    select * from testinzigzag
    where Name like ?
    <sql:param value="${row4.UpperTier}" />
    </sql:query>
    <c:forEach var="row5" items="${result5.rows}">
    ${row5.UpperTier}
    </c:forEach>

    </c:when>
    </c:choose>

    </c:forEach>
    </c:when>
    </c:choose>

    </c:forEach>
    </c:when>
    </c:choose>

    </c:when>
    <c:when test="${row2.UpperTier=='NA'}">
    No Upper Tier
    </c:when>
    </c:choose>
    </c:forEach>
    </c:when>
    </c:choose>

    I can only code it in a way that it is not done in a loop. Assuming i have 50 tiers, I would have to do it 50 times. Is there a way that I can do it in a loop?
    Last edited by danpj; 07-17-2009 at 10:00 AM. Reason: Unfinished

Similar Threads

  1. [SOLVED] Getting Data from a database
    By AJG in forum New To Java
    Replies: 8
    Last Post: 04-04-2008, 01:52 PM
  2. Replies: 0
    Last Post: 03-11-2008, 05:55 PM
  3. Retreiving list of keys from Map with certan value
    By desmond5 in forum New To Java
    Replies: 1
    Last Post: 03-06-2008, 09:10 PM
  4. Replies: 1
    Last Post: 02-01-2008, 02:21 PM
  5. How to query data from database using SSL
    By mano in forum New To Java
    Replies: 0
    Last Post: 08-02-2007, 06:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •