This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes Unable to match database value with string Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Unable to match database value with string" Watch "Unable to match database value with string" New topic
Author

Unable to match database value with string

vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
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");
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35253
    
    7
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 ]

Android appsImageJ pluginsJava web charts
vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
Thank you Ulf Dittmer. Works perfectly now.
 
 
subject: Unable to match database value with string
 
Similar Threads
How to use Enum for Range Comparison
ResultSet problem
Downloading and saving/opening a file
ResultSet problem
Column count doesn't match value count at row 1