Return statement and Try Catch problem

Hi!!

I've got the next code:

public ResultSet DBSelectTeam(String query) {

try {

Statement s = con.createStatement();

ResultSet rs = s.executeQuery(query);

return rs;

} catch (Exception err) {

JOptionPane.showMessageDialog(null, "ERROR: " + err);

}

}

But I need a return statement in the catch-block, but I don't know what's the best option.

Help...

Many thanks.

[451 byte] By [link_neta] at [2007-10-2 1:45:34]
# 1

I've never used them, but I understand in a case like this, it might be best to use a throwable - and make your method throw something if it fails.

Otherwise, probably the best thing to do is to return the value null. (I don't know if a ResultSet can have the value null, so if it can't then this would not be the thing to do. But if it can, then this would problably be the simplest thing to do)

dlorimera at 2007-7-15 19:09:41 > top of Java-index,Desktop,Core GUI APIs...
# 2
I'm always partial to adding a return null; statement when it fails then handling the null within the calling method.
javanator2000a at 2007-7-15 19:09:42 > top of Java-index,Desktop,Core GUI APIs...
# 3
Ok, many thanks!! :)
link_neta at 2007-7-15 19:09:42 > top of Java-index,Desktop,Core GUI APIs...
# 4
A lenghtier discussion can be found in the cross-post: http://forum.java.sun.com/thread.jspa?threadID=670338@link_net: Please do not cross-post. You are wasting peoples time, and that's not very nice, don't you agree?
happy_hippoa at 2007-7-15 19:09:42 > top of Java-index,Desktop,Core GUI APIs...
# 5
Hi happy_hippo :)Yes, I agree... and I'm sorry :(( I sent my post to this forum (Swing), but later I realized it was better in Java Programming. That's the reason why I followed replying in Java Programming and not in this forum.Sorry again :(
link_neta at 2007-7-15 19:09:42 > top of Java-index,Desktop,Core GUI APIs...
# 6
> > Sorry again :(No big deal :-)
happy_hippoa at 2007-7-15 19:09:42 > top of Java-index,Desktop,Core GUI APIs...