wood burning stoves 2.0*
The moose likes JDBC and the fly likes Help on how to use my return TRUE value from an Stored Procedure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Help on how to use my return TRUE value from an Stored Procedure" Watch "Help on how to use my return TRUE value from an Stored Procedure" New topic
Author

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

Peter Hammar
Ranch Hand

Joined: Mar 01, 2010
Posts: 34
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

Joined: Oct 13, 2005
Posts: 36453
    
  15
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

Joined: Mar 01, 2010
Posts: 34
So how do I write



correclty?

Regards
Peter
Mark Waes
Greenhorn

Joined: Aug 06, 2008
Posts: 21
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

Joined: Mar 01, 2010
Posts: 34
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

Joined: Aug 06, 2008
Posts: 21
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

Joined: Mar 01, 2010
Posts: 34
It needs a String as a IN parameter?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
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

Joined: Mar 01, 2010
Posts: 34
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
 
subject: Help on how to use my return TRUE value from an Stored Procedure
 
Similar Threads
RequestDispatcher method is not working.
Alphabet Pyramid
Connection with database Help
Getting strange error when trying to call another procedure
Simple JDBC problem - Connection throws Nullpointerexception