Problem with Multiple String comparision

[nobr]Iam sending some values to another page where updation talkes place

In this update page Iam comparing the string values i.e the existing values with the entered ones in the first page.

If both are equal then updation won't take place or else it will update.

Problem is when only one value is changed in the first page , it should update as it is an OR condition

but updation doesn't happen here.If I change all the three variables then updation happens.

How can I update when a single variable is changed in the first page.

String implemented_suggestions1,suggestion_registered_no1,remarks1;

String implemented_suggestions[],suggestion_registered_no[],remarks[];

for(int k=0;k<rowid.length;k++)

{

x="select implemented_suggestions,SUGGESTION_REGISTERED_NO,REMARKS from EMP3 where and rowid='"+rowid[k]+"' ";

rsx=stx.executeQuery(x);

if(rsx.next())

{

implemented_suggestions1 = rsx.getString(1);

suggestion_registered_no1 = rsx.getString(2);

remarks1 = rsx.getString(3);

//Comparision between String and String array

if(implemented_suggestions1.equals(implemented_suggestions[k]) || suggestion_registered_no1.equals(suggestion_registered_no[k]) || remarks1.equals(remarks[k]))

{

out.println("><BR>NOT UPDATED<BR>");

}

else

{

y="update EMP3 set IMPLEMENTED_SUGGESTIONS='"+implemented_suggestions[k]+"',SUGGESTION_REGISTERED_NO='"+suggestion_registered_no[k]+"',REMARKS='"+remarks[k]+"',DATE_OF_UPDATE=to_date(sysdate,'dd/mm/yy') where rowid='"+rowid[k]+"'" ;

z=st.executeUpdate(y);

if (z==1)

{

out.println(" updated Successfully");

}

else

{

out.println("not updated");

}

}

}

}//END OF FOR

[/nobr]

[2717 byte] By [cgsa] at [2007-10-2 16:06:27]
# 1
The == operator tests whether two objects are the same object, not whether they hold the same data. Strings are objects, not primitives. So test Strings using equals().Drake
Drake_Duna at 2007-7-13 16:45:19 > top of Java-index,Java Essentials,New To Java...
# 2
Also, "updation" is not a word.Drake
Drake_Duna at 2007-7-13 16:45:19 > top of Java-index,Java Essentials,New To Java...
# 3

[nobr]I hope that I have checked using the .equals().My problem is if i change all the three values in the first page then I am able to update but not for one value...Is there any problem in this code

if(implemented_suggestions1.equals(implemented_suggestions[k]) || suggestion_registered_no1.equals(suggestion_registered_no[k]) || remarks1.equals(remarks[k]))

{

out.println("><BR>NOT UPDATED<BR>");

}

[/nobr]

cgsa at 2007-7-13 16:45:19 > top of Java-index,Java Essentials,New To Java...
# 4

[nobr]if(implemented_suggestions1.equals(implemented_suggestions[k]) ||

suggestion_registered_no1.equals(suggestion_registered _no[k]) ||

remarks1.equals(remarks[k]))

{

out.println("><BR>NOT UPDATED<BR>");

}

The problem is that with an OR statement only one condition needs to be

true. So if suggestion_registered_no1 has changed and needs to be

updated but implemented_suggestions1 is the same it will evalute to true

and no update occurs.

I would flip your logic around:

if(! implemented_suggestions1.equals(implemented_suggestions[k]) || etc)

{

//perform update

}

[/nobr]

floundera at 2007-7-13 16:45:19 > top of Java-index,Java Essentials,New To Java...
# 5
Thanks flounder, your logic really worked.
cgsa at 2007-7-13 16:45:19 > top of Java-index,Java Essentials,New To Java...