|
-
problems with Float.parseFloat()
Hi,
I am writing a pgm in which I need to calculate the total proce of all
the products selected by the user on the GUI.but then I am using IBM JDK
1.1.7 ,,,so I am getting an error with
Float.parseFloat() method, I think the method is not existing in the jdk1.1.7
API, but then I dont know how to slove the problem, I am giving the code
below for the program, could anyone have a look at it and solve my problem....
Satish
-----------------------------------------------------------------
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class cart extends HttpServlet
{
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
public void init(ServletConfig sc) throws ServletException
{
try
{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
con = DriverManager.getConnection("jdbc:db2:sample","webs",
"websdba");
super.init(sc);
}
catch(Exception e) {e.getMessage() ; }
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String TotalPrice = new String();
res.setContentType("text/html");
PrintWriter out = res.getWriter();
HttpSession session = req.getSession(false);
Object[] items = (Object []) session.getValue("cart.items");
out.println("<html> ");
out.println("<body bgcolor = white >");
out.println("<H3>you currently have the following items in your cart:</H3><br>");
out.println("<form> ");
out.println("<table>");
if( items != null )
{
for (int i = 0 ; i < items.length; i++ )
{
try
{
String str1 = (String) items[ i ] ;
pst = con.prepareStatement("select PRICE from ITEMTAB where
ITMNAME = ? " );
pst.setString(1,str1);
rs = pst.executeQuery();
while(rs.next())
{
String curprice = rs.getString("price");
out.println("<tr>");
out.println("<td> ");
out.println( "The Price of " + "
" + str1 + " is " + " " + curprice );
out.println("</td> ");
out.println("</tr>");
out.println("</table>");
out.println("<br>");
String totalval = "0.0" ;
session.putValue("total.cost", (new Float(Float.parseFloat(totalval)
+ Float.parseFloat(curprice)).toString()) );
}
}
catch(Exception e) { e.getMessage(); }
}
out.println("<table border = 1 cellpadding = 2 cellspacing = 3>");
out.println("<tr>");
out.println("<td>");
String totval = (String)session.getValue("total.cost");
out.println("The Total Cost of all the Products in the Cart is : " +
totval );
out.println("</td>");
out.println("</tr>");
out.println("</table>");
out.println("</form>");
}
else
{
out.println("There are no items in the session value for cart.items"
);
}
out.println("</body>");
out.println("</html> ");
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks