Hi, i need to do this:i had initialized an extension number in the string Caller.I had a table dnc having fields name and callerid.i have to check whether the caller i have initialised is equal to any of the caller id in that table.if the caller is in the database, i have to display a message "dont call this number".if the caller is not in the database i have to display the number.since it is very easy, i am not getting the output.my code follows:please help me where i am wrong. . It is displaying the output as 5103.where i am wrong.
thanks.I've tried that too.Now i am getting the output "Dont call this number".But if i change the Caller number to a number which is not in my database,it should display that number.But it displays nothing.what is the wrong in my code.Why it is not taking the else part?
posted 11 years ago
If i hardcode any number which is inside my database in the query like this
select * from dnc where callerid="5101"
. I am getting output for if part as DOnt call this number,if the String Caller="5103"; even if changed the String caller="5110"which is not in the database,it displays the same number 5110 as i have mentioned in the else part. but I dont know why i am not getting the output for else part when my query is like this: select * from dnc where callerid='"+Caller+"'.
Originally posted by preethi Ayyappan: thanks.I've tried that too.Now i am getting the output "Dont call this number".But if i change the Caller number to a number which is not in my database,it should display that number.But it displays nothing.what is the wrong in my code.Why it is not taking the else part?
See my earlier post. Your logic means your output will only happen if a record with the defined callerid exists.
You have a conditional check, where you tests the equality of Caller with what is returned by your query. This is a pointless check, since you know this is equal if your query returned something. This check is done inside the while loop you are using to navigate through your ResultSet. So if your query returns no results (as it will if a record with your callerid does not exist) this code will not be run. This check needs to be changed so it is run if your ResultSet is empty.