File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes using jstl formatNumber with rs.getString Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "using jstl formatNumber with rs.getString" Watch "using jstl formatNumber with rs.getString" New topic

using jstl formatNumber with rs.getString

Carl Zeigler

Joined: Mar 09, 2010
Posts: 5
Hi, I am trying to use the formatNumber function to display a string value returned from a database via rs.getString(). I have been testing the formatNumber function and see how it works but I cannot figure out how to pass the string returned from the database into the value parameter of the formatNumber fucntion. Is there any way I can do this?

Thank you.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62749

Mixing scriptlets and JSTL/EL in a JSP page is recipe for complete and utter disaster.

You should do two things in order of importance:

  • Never ever, and did I mention ever, send a resultset to a JSP. Rather, copy the data from the resultset into a Java collection immediately after fetching it and release the resultset. This collection (List, array, whatever) is what gets sent to the JSP.
  • Use no scriptlets or other Java code in a JSP. That's a practice that has been discredited for almot 10 years now.

  • [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Miku Ranjan
    Ranch Hand

    Joined: Oct 11, 2011
    Posts: 98
    As it is described in the last post you should use jstl/EL and for your scenario you can use a pattern attribute to describe the number format in the jstl tag, formatNumber.
    Stefan Evans

    Joined: Jul 06, 2005
    Posts: 1407
    It should probably also be pointed out that the "formatNumber" tag takes a number (ie Integer, Double etc) and turns it into a String.
    The value you are passing in is already a String.

    If what you are getting from the database is a number, I would recommend using the rs.getInt() or rs.getDouble() methods rather than rs.getString().

    I agree. Here's the link:
    subject: using jstl formatNumber with rs.getString