tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Knox <jk...@lvcm.com>
Subject Re: JSTL and EL question
Date Tue, 03 Jun 2003 16:16:04 GMT
Oh boy, I get to contribute after asking a lot of questions!  ; )

Here's a query I am using in a current project:

<sql:query var='picks' maxRows='1'>
   select * from contestant_picks where contestant='q' and week = ? 
order by entered desc
   <sql:param value='${thisWeek}'/>
</sql:query>

I am using the maxRows option mainly because I don't need the db 
returning all of the older data. Hmm, now that I think about it I can 
probably add "and entered = max(entered)" or something like that. 
Anyway, what I learned was that . and [] differed in an important way. 
You can't evaluate a variable after the . but you can inside the []. As 
a result my code worked out to:

   <c:set var='gameNum' value='game${game.game}'/>
   <c:set var='thisPick' value='${picks.rows[0][gameNum]}'/>

The gameNum variable will contain a string like "game1", "game2', etc. 
These are the names of the columns in the table. The second line 
replaces the gameNum variable inside the [] so I get the equivalent of 
"picks.rows[0].game1". One other piece you are missing is "rows" from 
the value. As a result the following code should work for your 
situation:

<c:out value='${superData.rows[0][user_id]}'/>

I would highly recommend the book "core JSTL Mastering the JSP Standard 
Tab Library" by David M Geary from Sun. It got me up to speed on JSTL 
in less than a week. Now I can't wait for Tomcat 5 to support JSP 2.0.

Hope this helps,

Jeff


On Tuesday, June 3, 2003, at 05:49  AM, Nikola Milutinovic wrote:

> Hi all.
>
> I'm using JSTL (Java Standard Tag Library), the EL (Expression 
> Language) version. I have a DB where one particual query can return 
> exactly one row (primary key). So, I use this:
>
> <sql:setDataSource dataSource="jdbc/EVracunDS"/>
> <sql:query var="userData">
>   SELECT * FROM user_tab WHERE user_id = ?
>   <sql:param value="${userID}"/>
> </sql:query>
>
> This works just fine and I can iterate over it using <c:forEach>.
>
> <c:forEach items="${userData}" var="userRow">
> ...
> </c:forEach>
>
> I would like to be able to access the row directly, since I'm 100% 
> sure there will be only one. Trying this, fails:
>
> <c:out value="${suerData[0].user_id}"/>
>
> or
>
> <c:set var="userRow" value="${userData[0]}"/>
>
> Can anyone advise?
>
> JSTL implementation is Jakarta-Standard-1.0.3
>
> Nix.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message