in the pgm i want to trap the individual cost of each product from the database
and then put in a session...until the rs.next() loop iterates and then finally
add the costs of the products into totalcost and then displsy it on to the
screen..that is the functinality to be achieved. i am getting the individual
costs diplayed on the screen, but i am not able to add them into totalcost
variable and display them...if u understood the problem pls tell me the solution
satish
PLS CHECK THE CODE BELOW AND LET ME KNOW WHERE I AM GOING WRONG
out.println("<html> ");
out.println("<body bgcolor=899699>");
out.println("<H3>you currently have the following
items in your cart:</H3><br>");
out.println("<form> ");
else
{
out.println("There are no items in the session
value for cart.items" );
}
out.println("</body>");
out.println("</html> ");
}
}
08-30-2000, 12:37 PM
Nikhil
Re: PLS CHECK THE CODE
Hi,
I hope two things you should do for this.
1) It is better to read from the database once using RS.getXXX();
Please in the loop, get the price() ( rs.getString("price"))) and assigned
it to a variable ( say curprice).
2) After showing to the page first get the session value session.getValue("total.cost")
and assigned to a variable ( say totprice), and then put the value with (
totprice + curprice ) with float value.
I hope it will work
Nikhil
"SATISH" <SATISH141@ENGLAND.COM> wrote:
>
>
>
>DEAR BADRI,
>
>
>in the pgm i want to trap the individual cost of each product from the database
>and then put in a session...until the rs.next() loop iterates and then finally
>add the costs of the products into totalcost and then displsy it on to
the
>screen..that is the functinality to be achieved. i am getting the individual
>costs diplayed on the screen, but i am not able to add them into totalcost
>variable and display them...if u understood the problem pls tell me the
solution
>
>satish
>
>PLS CHECK THE CODE BELOW AND LET ME KNOW WHERE I AM GOING WRONG
>
>
>
>import java.io.*;
> import java.sql.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
>
>
>
> 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",
>"satish", "london");
>
> super.init(sc);
>
> }
>
> catch(Exception e) {e.getMessage() ; }
>
> }
>
>
>
>
>
>
>
> public void doPost(HttpServletRequest req, HttpServletResponse res)
>throws ServletException, IOException
> {
>
>
>
>
> res.setContentType("text/html");
> PrintWriter out = res.getWriter();
>
> HttpSession session = req.getSession(true);
>
> Object[] items = (Object []) session.getValue("cart.items");
>
>
> out.println("<html> ");
> out.println("<body bgcolor=899699>");
> out.println("<H3>you currently have the following
>items in your cart:</H3><br>");
> out.println("<form> ");
>
> out.println("<table border = 2 cellpadding=2 cellspacing=3
>>");
>
> if(items!=null)
> {
>
> for (int i = 0 ; i < items.length
>; i++ )
> {
>
> try
> {
>
> String[] cost
=
>new String[3];
>
>
> pst = con.prepareStatement("select
> * from ITEMTAB where itmname = ? " );
>
> String str1 =