aspose file tools*
The moose likes Java in General and the fly likes Particular try block not executing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Particular try block not executing" Watch "Particular try block not executing" New topic
Author

Particular try block not executing

Ravi Harishchandra
Greenhorn

Joined: Oct 29, 2012
Posts: 17
Hi....I have written a java program in which I have used 2 try-catch blocks. Each try block consists of SQL queries to
updates the database. But the first try block just does not execute. The second one works fine. The connection settings and everything is the same in both.
please help me out on this.

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4461
    
    8

Obviously, there's no way we can know what the problem is without seeing the code.

The first thing I'd check, though, is that it's really true that "the first does not execute". Put some logging statements in there. Maybe it's executing but not causing an update for some reason.

Oh, and make sure that you are doing something with any exceptions that you catch, and you don't have any catch(Exception e) {} blocks in there.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11475
    
  16

How do you know that it does not execute? how do you know it SHOULD execute?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ravi Harishchandra
Greenhorn

Joined: Oct 29, 2012
Posts: 17
Hii Mathew and fred...

The exception statements are added. I did not mention it to reduce the complexity. The first try block has to execute... since it is sending values
to back end. And there are no IF or CONDITIONAL statements to prevent it from executing....I'm posting the codE:
[Added code tags - see UseCodeTags for details]
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4461
    
    8

So how do you know it isn't executing? I can't see anything in that code that would make me certain. There's not a single line that prints any output regardless of the results of the query, for instance.

Stick some System.out.println() statements in there to find out exactly where the code flow is. Because it's not possible for the code to be ignoring the first block and executing the second.
Robert Simmons Jr.
Author
Greenhorn

Joined: May 26, 2004
Posts: 2

Well there are a lot of things wrong with the code you posted but it could be that the first block is throwing an exception and it is being caught and thrown to system console but since you arent doing e.printStackTrace() you arent seeing the exception. The toString method of an exception doesn't necessarily print the stack trace it might just print something like com.java.foo.Exception@91480914

Try not catching the exception and try inserting some print statements to trace execution.


-- Robert Simmons Jr.

Author: Maintainable Java
http://www.amazon.com/Maintainable-Java-ebook/dp/B00AKHI69K/ref=sr_1_2?ie=UTF8&qid=1355159024&sr=8-2&keywords=Maintainable+Java
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2364
    
  50
My guess is the code is running but you are getting an empty result set.
Have you tried running your sql statement "select * from delux" directly on your database (ie from a command line utility or GUI front end such as Toad) to see if it actually returns anything.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8



I'm not sure why you say this is an important distinction. The isBeforeFirst method returns a boolean value which tells you whether the ResultSet's cursor is before the first row or not. But you ignore the return value. In other words, that line of code does nothing at all.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Particular try block not executing