Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Unable to match database value with string

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to redirect my user based on the value in the database but somehow my code doesnt seem to work. Even if the value of Status is "Pending" in the database it goes to

response.sendRedirect("deletestudentlist.jsp"); instead of

response.sendRedirect("viewstudentlist.jsp");

The problem i presume is in (status1 == "Pending") but not sure what is wrong. Please do help. Thank you.



rst1 = stm1.executeQuery("select Status from appraisal");
String status1 ="";
while(rst1.next()){
status1 = rst1.getString("Status") ;

}

if(status1 == "Pending"){
response.sendRedirect("viewstudentlist.jsp");
} else{
response.sendRedirect("deletestudentlist.jsp");
}
 
Rancher
Posts: 43075
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strings are not compared using "==", they're compared using the "equals" method. "==" tests the equality of the two String references, not the equality of the string contents.
[ October 25, 2006: Message edited by: Ulf Dittmer ]
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ulf Dittmer. Works perfectly now.
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic