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.
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
Joined: Oct 29, 2012
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]
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.
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.
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.
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.