File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to get callerid through jdbc

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so,what should i do exactly?
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me to correct my query
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 518
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 518
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 518
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where i have to modify my code to get the proper outputs which i need?
Where i am wrong?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 518
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then how should i check the condition.please guide me
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if (Caller.equals(callerid))

.In the place of callerid,what should i give.could you show me in code?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 518
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thank you for your help.I got the result.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic