Please correct my English.
Please correct my English.
Matthew Brown wrote:When you say "not working", it's helpful to give more details.
Paul Clapham wrote:
Matthew Brown wrote:When you say "not working", it's helpful to give more details.
statement at the the end of class.return null
Paul Clapham wrote:Don't ever put a return statement inside a finally block. That overrides any returns you might have done in the try statement. (Yes, you do have a return statement inside a finally block, it's just that the irregular indentation hides that fact.)
It's all right to put the return statement after the finally block.
Paul Clapham wrote:When you say "nothing returns" what does that mean?
nermin vucinic wrote:It means when I run this method (getFromId) from main class (Sales), it should return new class instance(Product p), with its field values, but it returns nothing.
Matthew Brown wrote:
nermin vucinic wrote:It means when I run this method (getFromId) from main class (Sales), it should return new class instance(Product p), with its field values, but it returns nothing.
I assume you mean null is returned, which isn't quite the same thing. Anyway, assuming the return null is now in the right place, the possible explanations for that that I can think of are:
- An exception is thrown somewhere (though you should get something written to System.out in those cases)
- The query isn't returning a match for the given ID
You can put some debugging lines in to check if it's the latter - does rs.next() return false? If so, I think the next step would be to check that the ID value being passed in is what you think it is, and that the database contains what you think it does.
Matthew Brown wrote:Sorry, but none of your posts are really giving us enough information to help us help you.
By now, by either running through a debugger or adding debugging code (print statements, etc), you should have been able to:
a) Confirm that the method has been called in the first place
b) Confirmed exactly where the method is returning from
That might give us a clue where to look next.
It might be worth posting the current version of the method, and tell us exactly what path through the code is being taken.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |