This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Particular try block not executing

 
Ravi Harishchandra
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know that it does not execute? how do you know it SHOULD execute?
 
Ravi Harishchandra
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tony Docherty
Bartender
Posts: 2952
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20958
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic