It's not a secret anymore!
The moose likes Servlets and the fly likes jsp:compare select statement error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "jsp:compare select statement error" Watch "jsp:compare select statement error" New topic

jsp:compare select statement error

shaz akhtar

Joined: Jan 01, 2005
Posts: 11
Hello everyone

I am doing my project on a shopping cart. i have a little problem! ive got 2 tables..products and tempcart. The products table contains the fields idnumber and all the rest of the product information (such as title, description). The tempcart table has 2 fields. sessionid and idnumber. Each time a user selects an item, the idnumber and the sessionid is inserted into the tempcart. It works so far!! however the problem is i want to find out what products has that particular user selected during that session not products selected by all users. At the moment when the user selects a product they want to purchase i get a blank page of the cart and does not show the product details. the code i am usinmg is as follows:

<%@ page import="java.sql.*, java.util.*,* " session="true" %>


java.sql.Connection con1 = null;

Statement stmt1 = null;
ResultSet rs1 = null;
String queryStr1 = null;
String usernamereg1 = request.getParameter("usernamereg");
String strsessionid = request.getParameter("sessionid");
con1 = DriverManager.getConnection(

stmt1 = con1.createStatement();
queryStr1 = "select * from products prod, tempcart cart where prod.idnumber=cart.idnumber AND cart.sessionid = '"+ strsessionid +"'";
rs1 = stmt1.executeQuery(queryStr1);

User <font color = "red"><b><%=usernamereg1%></font></b> Logged In
<font size=5>Shopping Cart</font>

<form action="deletecart.jsp" method=post>
<table cellpadding=2 cellspacing=2 align="right" border=1 width="70%">

while (
String idnumber = rs1.getString(1);
String title = rs1.getString(2);
String description = rs1.getString(3);
String category = rs1.getString(5);
String price = rs1.getString(6);
String image = rs1.getString(7);


<tr><td valign = 'Top'><input type="radio" name="dvddownload" value="<%=idnumber%>"</br></td>
<td valign = 'Top'> <%=title%> </td>
<td valign = 'Top'> <%=description%> </td>
<td valign = 'Top'> <%=category%> </td>
<td valign = 'Top'> <%=price%> </td>
<td valign = 'Top'> <img src="<%=image%>" border=1 width=90 height=120"> </td>
<td valign = 'Top'><input type="submit" name="removetempcart" value="Remove" </td>


} // end while ()
}catch(SQLException s) {%> <%= s%> <% }
//clean up.
if (rs1!=null) rs1.close();
if (stmt1!=null) stmt1.close();
if (con1!=null) con1.close();
}catch (SQLException s) {}

<td align=center colspan=2>



<form action="check2.html" method=post>
<input type="Submit" value="Checkout">
<form action="list.jsp" method=post>

<input type="submit" value="Continue Shopping">

<input type="hidden" name="sessionid" value="<%=session.getId()%>"



i have got the sessionid as a hidden field, convert it to a string and compare it in the select statement.but it still doesnt work. I would really appreciate if anyone can help me with this.

thanks shaz!!!
Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
Two questions:

Could the problem be on any of your other pages ? In particular, it might help if you list your "list.jsp" (assuming that's the one that allows users to add items to their shopping cart).

Is there a special reason why you chose to use a hidden field to deliver the sessionID to/from the browser ? To the best of my knowledge this approach is a bit un-usual : people usually prefer to just call:

and rely on the session ID to travel *automatically* between client and server, relying on either cookies or "url rewrites" (it does, however, mean that either you ask your users to enable cookies on their browser, or you use the "encodeURL" statement whenever you render a link).
shaz akhtar

Joined: Jan 01, 2005
Posts: 11
thanks so much that worked
im passing most values that i need from one jsp page to another in hidden fields, is there are a better way of doing it?
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

For starters, there's no need to pass the sessionId this way.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
Passing parameters between pages:
it might be useful to store shared data under your "session" (or under "application", if you'd like the datum to be viewed by *all users*, not just by the user who entered it).
A simple example :

you might also want to have a look at the apache Struts framework (or the new "Java Server Faces" ).
It involves *considerably* more work (deploying jar files, creating java classes, editing xml files), and I would *not* recommend it for a very simple test program. But my company does use it for "real world" applications, where it proved priceless.
I agree. Here's the link:
subject: jsp:compare select statement error
It's not a secret anymore!