File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes returns true, but if ( block not executed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark " returns true, but if ( block not executed" Watch " returns true, but if ( block not executed" New topic
Author returns true, but if ( block not executed

Woody Dvorak

Joined: Sep 15, 2009
Posts: 3
In the following method:

At line #20... if ( - the resultset contains a record, returns true (I checked using a breakpoint), but the statements in the if block are not executed. The code jumps immediately to the finally block.

This is happening in several (new) methods I've written, but older methods containing similar logic / syntax are working fine.

What is wrong???

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33134

Welcome to JavaRanch! always returns true on "select count(*)". The question is whether the count is greater than zero.

Can you try the following to see what the value of the count is?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Woody Dvorak

Joined: Sep 15, 2009
Posts: 3
Hi, Jeanne... thanks for the response (and the welcome)!

I agree, my expectation is (as you pointed out) that I'll always get a RecordCount returned from this query, even if there are no matching records... and I am.

To reiterate, I put a breakpoint at line 20, examined the value of the expression it's true. But when I continue execution (step over), it doesn't execute the next statement in the if block... it jumps directly to the finally block. Seems impossible (!)... but that's what it's doing, consistently.

Using Eclipse JEE (Ganymede), app is deployed on JBoss 4.2.2, Oracle back end. No errors in JBoss log, no exceptions, no nothing... just weird. I've showed the behavior to a couple of other guys here, we're all scratching our heads. I've redeployed (many times), restarted JBoss, rebooted the server... no luck resolving this. Been fighting it for days...

BTW, this is a DAO class... and, as you can see, the connection is method-scoped. Also, I've copied the strSQL variable (while in break mode), pasted into Toad & executed... worked fine, returned a RecordCount of value 2 (or other value, depending on userSsn). I just can't get the code to continue executing the statements inside the if block...

Woody Dvorak

Joined: Sep 15, 2009
Posts: 3
I put println statements in the if block and the catch block - not executing either of 'em. <sigh>

I'm playing around with Connection scoping, now... I wonder if using these similarly-named connections / statements / resultsets within multiple methods, within multiple DAO's might be introducing a conflict?
David Kilcy

Joined: Aug 25, 2009
Posts: 20
try catching Throwable just as an experiment. Maybe you're getting a runtime exception thats not being caught.

On a side note, you should also put an independent try/catch around each "close()" statement. If one of your close statements throws an exception it will not finish the rest of your cleanup, and you will be leaking resources.
I agree. Here's the link:
subject: returns true, but if ( block not executed
jQuery in Action, 3rd edition