I made the changes in your code below.

-----Original Message-----
From: Rich Tretola [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 04, 2001 8:56 AM
To: JRun-Talk
Subject: RE: RS Formating


OK here is my code.  How do I format the UnitPrice into a dollarformat?

<html>
<head>
<title>Database QRY</title>
</head>
<%@ page import="java.sql.*" %>
<body>

<table align="center" width="100%" border="1">
<th colspan="3" align="center">Products</th>
<tr>
<td><strong>Product Name</strong></td>
<td><strong>Unit Price</strong></td>
<td><strong>Units In Stock</strong></td>
</tr>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection get_products =
DriverManager.getConnection("jdbc:odbc:happytoad");

Statement stmt = get_products.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Products order by
ProductName");

java.text.NumberFormat nf = java.text.NumberFormat.getCurrencyInstance();

while (rs.next())
{
   String ProductName = rs.getString("ProductName");
   double UnitPrice = rs.getDouble("UnitPrice");
   String UnitsInStock = rs.getString("UnitsInStock");
   out.print ("<tr>");
   out.print ("<td>" + ProductName + "</td>");
   out.print ("<td>" + nf.format(UnitPrice) + "</td>");
   out.print ("<td>" + UnitsInStock + "</td>");
   out.print ("</tr>");
}

get_products.close();
%>
</table>
</body>
</html>

Thanks,
Rich

-----Original Message-----
From: Christophe Coenraets [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 03, 2001 11:41 AM
To: JRun-Talk
Subject: RE: RS Formating


Use the formatting classes in java.text, for example java.text.NumberFormat.

Here is an example:

<%
        java.text.NumberFormat nf =
java.text.NumberFormat.getCurrencyInstance();

        // your sql stuff here

        while (rs.next()) {
%>
                <%= nf.format(rs.getDouble("price")) %>
<%
        }
%>

This is also a great opportunity for creating a custom tag.

Christophe

-----Original Message-----
From: Rich Tretola
To: JRun-Talk
Sent: 9/3/2001 9:33 AM
Subject: RS Formating

How do I format a result set in JSP?
dolarformat, numberformat, dateformat, etc.?

Thanks,
Rich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to