jQuery in Action, 3rd edition
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: 63838

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] [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: 1580
    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: http://aspose.com/file-tools
    subject: using jstl formatNumber with rs.getString
    It's not a secret anymore!