aspose file tools*
The moose likes JDBC and the fly likes to get callerid through jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "to get callerid through jdbc" Watch "to get callerid through jdbc" New topic
Author

to get callerid through jdbc

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Your logic looks wrong. Your output code will only run if something is returned from this SQL:

so you'll only see something if there are records wit hthis callerid.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
so,what should i do exactly?
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
please help me to correct my query
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Sorry, misread your problem.

This is an test to check whether the value of Caller* equals the literal string "callerid", rather than the value of the variable callerid. Remove the quotes.



(* BTW, in Java the convention is to define variable names that start with a lowercase letter. This avoids confusion between variable names and types)
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
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?
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
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+"'.

please help to do this simple program
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Where i have to modify my code to get the proper outputs which i need?
Where i am wrong?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Then how should i check the condition.please guide me
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
if (Caller.equals(callerid))

.In the place of callerid,what should i give.could you show me in code?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The psedo-code would be something like:

So what you need to do is work out a way of flagging that the ResultSet was empty. Perhaps you could use a boolean, set to true if the ResultSet had any entires?
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi
Thank you for your help.I got the result.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: to get callerid through jdbc