Portal Home > Knowledgebase > Articles Database > JSP: JSTL SQL query


JSP: JSTL SQL query




Posted by BostonGuru, 01-14-2008, 05:39 PM
I have an sql table with two columns (var,value), and I am looking to retrieve the value of a specific row (where the var value is "usercount") via jstl: The "result" variable is theoretically a array, but the result of the query should only be 1x1 array. Is there a way to denote the first cell[0,0] and just grab the cell to save as a variable, rather than have to walk through the array?

Posted by utropicmedia-karl, 01-14-2008, 05:42 PM
Why isn't the 'result' varriable a resultset/rowset?

Posted by BostonGuru, 01-14-2008, 05:49 PM
Maybe thats what it is. I am not sure (I just started learning JSP this weekend). I guess my question is, is there an easy way to convert the 1x1 size of whatever format it is, to a regular variable?

Posted by utropicmedia-karl, 01-14-2008, 05:57 PM
You typically get a collection back and then operate on it as you see fit. It's not a 1x1 size unless that is what your result should be, and then still is wrapped in the collection. Regards,

Posted by BostonGuru, 01-14-2008, 05:59 PM
In this case it will always be 1x1, so is there a quick way to "unwrap it" from the collection without having to walk through the array?

Posted by stdunbar, 01-14-2008, 06:33 PM
You've got a few issues here. The first is that you should use a parameterized query, not insert a string directly. Something more like: But to answer your last question, no, there isn't a generic way to do this. I'm not sure what would be wrong with the code: This just output your value. And if you're wrong and there is more than one value then you'll find a bug at the same time.

Posted by GMikeL, 06-23-2008, 10:36 AM
You can set the start and end point of the result set. Example below will return the first row of the return set from the . Hope this helps you.

Posted by bhuvi, 07-11-2009, 05:01 AM
c:forEach var="row" items="${result.rows}"> this code output the rows...but can we store this output in a string variable... and also i have to use these values outside the



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
problem with DNS (Views: 674)
ServINT down again? (Views: 679)

Language: