You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Gisella Saavedra <gi...@yachay.net> on 2002/09/08 23:41:45 UTC

JSTL SQL library

is there a way to find out the data type (metadata) of the columns
retrieved thru a query?

I am transferring the "var" that comes back filled from a
<sql:query >  to another JSP page.  I want to format the data
depending on whether they are date columns, or text, or numbers??

Gis

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: JSTL SQL library

Posted by Gisella Saavedra <gi...@yachay.net>.
Thank you Shawn!  It worked!

-----Original Message-----
From: Shawn Bayern [mailto:bayern@essentially.net]
Sent: Sunday, September 08, 2002 7:43 PM
To: Tag Libraries Users List; gisellas@yachay.net
Subject: RE: JSTL SQL library


On Sun, 8 Sep 2002, Gisella Saavedra wrote:

> <c:forEach items="${sessionScope.hdf.rows}" var="row" >
> 	   <tr>
> 	     <c:forEach items="${row}" var="col" >
>              <td><c:out value="${col.value}"/></td>
> 	     </c:forEach>
> 	   </tr>
> </c:forEach>
> 
> The inner look picks up the values in the  rowsByIndex order.

Actually, ${row} here references a SortedMap; the order is lexical.

> I tried changing the inner loop to
> 
> <c:forEach items="${sessionScope.hdf.columnNames}" var="col" varStatus="s" >
>        <td><c:out value="${row[${col}]}"/></td>
> </c:forEach>
> 
> and it failed.

${} applies to a whole expression, not a variable.  Instead of

  ${row[${col}]}

simply write

  ${row[col]}

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: JSTL SQL library

Posted by Shawn Bayern <ba...@essentially.net>.
On Sun, 8 Sep 2002, Gisella Saavedra wrote:

> <c:forEach items="${sessionScope.hdf.rows}" var="row" >
> 	   <tr>
> 	     <c:forEach items="${row}" var="col" >
>              <td><c:out value="${col.value}"/></td>
> 	     </c:forEach>
> 	   </tr>
> </c:forEach>
> 
> The inner look picks up the values in the  rowsByIndex order.

Actually, ${row} here references a SortedMap; the order is lexical.

> I tried changing the inner loop to
> 
> <c:forEach items="${sessionScope.hdf.columnNames}" var="col" varStatus="s" >
>        <td><c:out value="${row[${col}]}"/></td>
> </c:forEach>
> 
> and it failed.

${} applies to a whole expression, not a variable.  Instead of

  ${row[${col}]}

simply write

  ${row[col]}

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: JSTL SQL library

Posted by Gisella Saavedra <gi...@yachay.net>.
I need some help here!

sessionScope.hdf is the Result variable from a query.

I'm having a problem with displaying the results of a query in the order
of the column names, without knowing the column names:

<c:forEach items="${sessionScope.hdf.rows}" var="row" >
	   <tr>
	     <c:forEach items="${row}" var="col" >
             <td><c:out value="${col.value}"/></td>
	     </c:forEach>
	   </tr>
</c:forEach>

The inner look picks up the values in the  rowsByIndex order.
I tried changing the inner loop to

<c:forEach items="${sessionScope.hdf.columnNames}" var="col" varStatus="s" >
       <td><c:out value="${row[${col}]}"/></td>
</c:forEach>


and it failed.


Does somebody know if there is a way to loop at the result of a query
and print the values as the columnNames order (which is the order
of the SELECT statement  columns?

I do not see the rationale of the rowsByIndex of having the query
columns in a different order
than the corresponding columnNames order.
In JDBC, I believe the ordinal position of the resulting columns is
the same as the order of the names in the SELECT list.


I'd appreciate some help.  Developing with JSTL is taking longer than
expected.

Thanks,

Gis

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL SQL library

Posted by Shawn Bayern <ba...@essentially.net>.
On Sun, 8 Sep 2002, Gisella Saavedra wrote:

> is there a way to find out the data type (metadata) of the columns
> retrieved thru a query?
> 
> I am transferring the "var" that comes back filled from a <sql:query >
> to another JSP page.  I want to format the data depending on whether
> they are date columns, or text, or numbers??

This isn't possible in JSTL 1.0.  We considered the feature, but it
presented some tricky technical issue (how to deal with errors retrieving
the metadata, for one), and we dropped it for JSTL 1.0.

An application that needs this information might be straining itself to
use JSTL for database access anyway.  If you'd like to use JSTL instead of
a servlet (or other Java-based component) to access your data, though, you
can likely use the <fmt:parseDate> and <fmt:parseNumber> tags in
conjunction with <c:catch> to "guess" whether the information is a date, a
number, or arbitrary text.  Note, however, that this logic will base
itself on the form of the data, not on its column's type.

Hope that helps,

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>