File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help on how to use my return TRUE value from an Stored Procedure

 
Peter Hammar
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!

Really don't know if I should post it here...but I am a beginner, but my boss seems to think that I am good in java...

So, here is my problem.

I use a package to fetch a value from the database (Oracle). It returns Y(true) or N(false). If it returns Y/TRUE I would like to create a SELECT statement that fetches the quantity and updates a field (later task).

How do I get the (DataCommon.getKolli() == true) to work? It throws me: getKolli can not invoke getKoll. java.lang.string in datacommon.

 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never write == true and never write == false. If you have real Boolean values, then you need nothing to test for truth and use the ! operator to test for falsity.

You need to check what type of return value you are getting from getKolli() and use that type. Don't use the == operator, which will almost certainly give incorrect results.

Moving thread as not a "beginning Java" topic. It would sit better in our databases forum.
 
Peter Hammar
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how do I write



correclty?

Regards
Peter
 
Mark Waes
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not incorrect in the sense it doesn't work, more that it is bad form.

I assume:

is a method which will return a boolean type, so when the method is evaluated it is like writing:


which doesn't make sense if you think about it.

So, you can simply drop the '== true' portion from your condition statement, and the same result will be achieved. To test for falsity you add the 'not' ('!') operator to the beginning:



The result is code which is easier to read and therefore maintain.

Hope that helps.
 
Peter Hammar
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for making things clearer!



But when I try:


I get an error. "getKolli can not invoke getKoll. java.lang.string in datacommon." If you look on the above code, what does getKolli return? Is it not an boolean value? The IN parameter is a string. Im confused....
 
Mark Waes
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming the code:

Is calling:

What do you notice about the signature of the method called in the if condition, and the signature of the method itself? (Summarised below)


 
Peter Hammar
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It needs a String as a IN parameter?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also never write
if (something) return true;
else return false;


Just write

return something;

If you want boolean return types, why are you getting "Y" and "N"? If that isn't part of an enumeration, you might get incorrect answers, eg with "y".

There is more than style to not writing == true. It is possible mistakenly to write = true, in which case you can inadvertently introduce errors.
 
Peter Hammar
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Waes wrote:Assuming the code:

Is calling:

What do you notice about the signature of the method called in the if condition, and the signature of the method itself? (Summarised below)




Well, the method is of an boolean type with a string as an IN parameter. The if has nothing of that.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic