• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Particular try block not executing

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 2
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic