Re: question about standard taglib sql

Kris Schneider <[email protected]>
Newsgroups gmane.comp.jakarta.taglibs.user
Message-ID <[email protected]>
Kris Schneider wrote:
> Jerry wrote:
> 
>> Steven F. Bell <sbell <at> frycomm.com> writes:
>>
>>
>>> Hello,
>>>
>>> I am using the standard taglib sql tag to query a database and large 
>>> text fields are coming back like:
>>> net.sourceforge.jtds.jdbc.ClobImpl <at> 94aa42
>>>
>>> What could be causing this, and is there any means to correct it, and 
>>> get the proper text back?
> 
> 
> JSTL will use ResultSet.getObject to retrieve your results. In some 
> cases, this will result in a Clob. If you're using JSP 2.0, you might 
> consider creating an EL function to process the Clob into a string. Or 
> you could take a bean-based approach that will also work with earlier 
> version of JSP. Obviously, a scriptlet will also get the job done. The 
> simplest way to convert a Clob into a String is:
> 
> long length = theClob.length();
> String s = theClob.getSubString(0, (int)length);

Sorry, I think that should be:

String s = theClob.getSubString(1, (int)length);

> Of course, that might not work depending on the length of the Clob, so 
> there are other ways to stream the Clob data:
> 
> Reader in = theClob.getCharacterStream();
> ...
> 
>>> Also, the results in the tag are alphabetical a-z, can this order be 
>>> changed around to match the field order in the database?
> 
> 
> You might want to look at using Result.getRowsByIndex instead of 
> Result.getRows to iterate through your results:
> 
> <c:forEach var="row" items="${results.rowsByIndex}">
>   <c:forEach var="col" items="${row}">
> 
> Result.getRowsByIndex returns an Object[][] instance where the first 
> dimension is a row index and the second dimension is a column index.
> 
> I hope that's right, it's been a while since I've been able to play with 
> JSP/JSTL stuff...
> 
>> Hi,
>>
>> I had the same problem because i used the datatype ntext of text of a 
>> sql server
>> database.
>> Using varchar instead of text resolved my problem.
>>
>> Hope this helps,
>> Jerry

-- 
Kris Schneider <mailto:[email protected]>
D.O.Tech       <http://www.dotech.com/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.