JDBC error with shopping cart


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JDBC error with shopping cart

  1. #1
    satish Guest

    JDBC error with shopping cart



    Hi,

    For my shoppping cart project I am trying use the code below...

    I am able to diaply the names of the items stored in the cart...but i want
    to display the corresponding item nos and their prices from the database......but
    i am not getting the values from the databse....pls examine the code below
    and let me know as to where I am going wrong...thanks in advance

    satish

    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;




    public class cart extends HttpServlet
    {



    Connection con = null;
    Statement stmt = 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=999999>");


    out.println("<H3>you currently have the following
    items in your cart:</H3><br>");





    if(items!=null)
    {


    for (int i = 0 ; i < items.length ; i++ )
    {


    try
    {

    stmt = con.createStatement();



    out.println("<form> ");

    out.println("<table> ");

    out.println("<tr> ");

    out.println("<td> ");

    out.println( items[ i ] );


    rs = stmt.executeQuery("select * from ITEMTAB where itmname
    = " + items[ i ] );


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


    while(rs.next())
    {

    out.println("<td> ");

    out.println( rs.getInt("itmno"));


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


    out.println("<td> ");


    out.println( rs.getInt("price"));


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

    }













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

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




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



    }

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





    }


    }

    else
    {
    out.println("There are no items in the session
    value for cart.items" );

    }



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


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






    }



    }






  2. #2
    satish Guest

    Re: JDBC error with shopping cart


    THIS ERROR IS SOLVED


    SATISH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center