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 =
(String) items[ i ] ;

pst.setString(1,str1)
;
rs = pst.executeQuery(
);




while(rs.next())
{
out.println("<tr>
");

out.println("<td> ");

out.println( "The Price of " + " " + items[i] + " is
" + " " + rs.getString("price"));

out.println("</td> ");
out.println("</tr>
");


out.println("</table>
");

out.println("<br>");





cost[ i ] =
rs.getString("price") ;



session.putValue("total.cost",
cost );



}








}

catch(Exception e) { e.getMessage()
; }

}



out.println("<table border
= 1 cellpadding = 2 cellspacing = 3>");
out.println("<tr>
");
out.println("<td>
");

Object[]
totcost = (Object [] ) session.getValue("total.cost") ;


out.println("The Total Cost of all the Products in the Cart is : " +
totcost );

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> ");

}


}