Solved

If....else...... end.

Posted on 2002-07-29
7
183 Views
Last Modified: 2010-03-31
Hi friend, here is the funny question. I have 2 variable, password and conpass, I need to make sure these 2 variable is the same value before I can process. What I have done is like below:

a.jsp
=====
<html>
<head>
...............
...............
...............

 <%
   String username = request.getParameter("username");
   String password = request.getParameter("password");
   String conpass = request.getParameter("conpass");
   
   out.println(password);
   out.println(conpass);
   
  if (password == conpass) {

           wasusr.connect();
        wasusr.insert(username,password,conpass);
        out.println("Registration Completed !!");
   } else {
        out.println("Make Sure it;s the same!!");
   }
             
  %>

When I out print the variable, it's shown both variable is the same but the statement, "Make Sure it's the same" prompt out also.

Any ideas??

I have odne some comparison before for "String", proven it's working for String also .
Please help.
0
Comment
Question by:foongkim1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 7187080
== tests if they are the same object.
To test string equality use the equals() method:

if (password.equals(conpass)) {
0
 

Author Comment

by:foongkim1
ID: 7187309
TQ.

0
 
LVL 92

Expert Comment

by:objects
ID: 7187337
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:foongkim1
ID: 7187541
objects, so sorry to recall this again.

My below code doesn't performt the comparison purpose?
Why?

***************
String username=request.getParameter("username");
String password=request.getParameter("password");

wasusr.connect();
ResultSet rs = wasusr.checkusr(username);

  if (rs.next()) {
     String checkpass = rs.getString("WA1002");
     out.println(username);
     out.println(password);
     out.println(checkpass);
     
     if (checkpass.equals(password)) {
 out.println("Compare OK!");
}
}

it's doesn't print out the "Compare OK!", not event perform the compare statemet (IF). Further more, WA1002, is a CHAR in database.....

pleaseeeee

0
 
LVL 92

Expert Comment

by:objects
ID: 7189294
the i'd say they aren't equal.
Print the value of the two strings to check. Maybe there are trailing spaces on one.
0
 

Author Comment

by:foongkim1
ID: 7189369
if (rs.next()) {
    String checkpass = rs.getString("WA1002");
    out.println(username);
    out.println(password);
    out.println(checkpass);

this statement already printed out and it's shown the value is the same.
0
 
LVL 92

Expert Comment

by:objects
ID: 7192148
Check for trailing spaces.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question