This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
If the method's return type is something other than void, then a return statement must be at the end of each possible execution path within the method.
For example, if the method includes an "if" statement, then there must be a return statement for both cases -- that is, whether the "if" code executes or not.
If the method's return type is void, then no return statement is needed. (It's implicit at the end of the method body.) [ April 11, 2006: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Feb 23, 2006
I have a callable statement declared locally in a method and I need to close this stament after it executes plus I need to return one of the values from the callable statment. So I need to write something like this :
Originally posted by Jean Fore: ...what's the use if interchange the order of 2 & 3? It is wrong right? ...
If you exchange 2 & 3, then the code will not compile because the line after the return statement would be unreachable.
I'm not sure what "close" does, but if it cuts off access to the object, then you could store the int value in a temp variable. This would allow you to close before returning from the method.
rs.execute(); int temp = rs.getInt(1); rs.close(); return temp; [ April 11, 2006: Message edited by: marc weber ]
Joined: Feb 23, 2006
Thanks Marc, But after closing the callable statement "rs.close()", can I get values from that 'rs' using "rs.getInt(1)"? The statement is already closed right? That's why I was asking about interchanging the code lines. Thanks -JEAN
There are two solutions that I can see here. The first is to create a temporary variable that you use to store the value returned by the getInt() method. Then you can call close() and then return the temporary variable. The second is to use a try...finally statement and call close() in the finally clause. This solution uses some knowledge of exception handling and may be more complex than needed. On the other hand, it also ensures that close() will be called whether or not an exception is thrown.