• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

If condition problem

hi,

Why is my If condition not getting executed properly. Anything wrong in code.

while(rs.next())
     {
        if ( rs.getString(2)== request.getParameter("product"))
                                {
                                System.out.println("CAME DOSN");                                
                                }
         else
             { System.out.println("ELSE part"); }
}

Even though value of rs.getString(2) is equal to value of  request.getParameter("product"). IF part is not getting excuted. Only else part been excuted.
I tried to see on console by having system.out.print.... Both values are identical.
 rs.getString(2)  =HELLO
request.getParameter("product")=HELLO
0
princehyderabad
Asked:
princehyderabad
  • 5
  • 3
1 Solution
 
objectsCommented:
>     if ( rs.getString(2)== request.getParameter("product"))


should be:

    if ( rs.getString(2).equals(request.getParameter("product")))
0
 
objectsCommented:
if the rs can return null then you should check for that also
0
 
objectsCommented:
== tests if the are the same object, equals() tests if the value of two objects is equal.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
princehyderabadAuthor Commented:
Okay equals works, but it is still going to else part.

if (rs.getString(2).equals(request.getParameter("product")))

                                {
                                  System.out.println("Print IF Part");
                                 response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                                        String newLocn = "errorUpload.jsp";
                                        response.setHeader("Location",newLocn);
                                }

as per my code it should redirect to errorUpload.jsp correct ? then why is it also following else part ...
0
 
objectsCommented:
what make u think it is executing the else block?
0
 
princehyderabadAuthor Commented:
My else part has this code:
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                                        String newLocn = "view_current_releases.jsp";
                                        response.setHeader("Location",newLocn);

And I see my page is directed to view_current_releases.jsp
0
 
objectsCommented:
can you post the comnplete if/else statement
0
 
princehyderabadAuthor Commented:
On I Used  <jsp:forward page="errorUpload.jsp" />  instead of my above code to redirect and it worked. Thanks for your time.

Meanwhile OBject do u hv to me to look: http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21396244.html
Code is working only need proper arragement of code here and there. I hv seen in past you were great help to me. Thanks.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now