• 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

Updating several consecutive columns in an Apache derby database

 
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following code:-



the code seems to falter on the 9th line i.e. rs = s.executeQuery ("SELECT.....FOR UPDATE")

I have carried out this exercise before when updating ONLY one column but trying to update several columns seems to cause a problem

any ideas on what might be wrong ?

Bob M
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does "seems to falter" mean? TellTheDetails
 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have added debugging lines which print out a message both before and after said line
The before message is printed but the after message is not

Bob M
 
Tim Moores
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean the code just stops executing without a trace? That seems unlikely. Is there somewhere an exception handler that suppresses exceptions?
 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the following code appears further down..................

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bob Matthews wrote:the following code appears further down..................

Unfortunately, it is illegible because of incorrect indentation. Please post it again with correct indentation.
 
Tim Moores
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From this excerpt it's unclear if printSQLException is ever called - is it? Does it print information somewhere where you will see it?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what I can see, you have a bug at line 58 that you will see clearly when you format your code correctly.  Read HowToFormatCode (that's a link).

Also, pick a formatting style and stick to it.  Either Allman:
or K & R:
 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
apologies.......................

 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am following the following example as regards error trapping

https://svn.apache.org/repos/asf/db/derby/code/trunk/java/demo/.../SimpleApp.java

 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bob Matthews wrote:apologies.......................

Proper code style helps you find some types of bugs quickly. It also says to us "please put some effort into helping me, I'm at least willing to put the effort in to properly indent my code". Take pride in your code. I'm afraid to say your attempt at formatting was haphazard. If you don't want to format by hand then invest the time into learning an IDE, or, look at the rudimentary indenter written in Java in the link in my signature. This was run through an Eclipse formatter.
 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes - I agree with your comments.....................

I have just spent some time with Netbeans and reformmated my whole program

I don't think there is a bug in the error trapping routine (as suggested)
and I still have my original problem

Bob M
 
Tim Moores
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand what all this exception handling code has to do with the original problem.

I'll say it again: code doesn't just stop running. If it appears so then there may have been an exception that was swallowed by some catch statement that ignores it (needless to say, not a good catch statement).

So:

From this excerpt it's unclear if printSQLException is ever called - is it? Does it print information somewhere where you will see it?

 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 10 coding was in error - requires string concatination

Thanks

Bob M
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bob Matthews wrote:Line 10 coding was in error - requires string concatination

Thanks

Bob M


Excellent catch! It looked correct enough that we overlooked it. A PreparedStatement would have caught that.
Congrats.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bob Matthews wrote:I have just spent some time with Netbeans and reformmated my whole program


For future reference, you only need this key sequence: Alt-Shift-F
 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Knute - thanks for that

Carey - my new lone reads as follows................



Is there a better way to code this ?

Bob M
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a prepared statement.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote: If it appears so then there may have been an exception that was swallowed by some catch statement that ignores it (needless to say, not a good catch statement).



And if I ever have to maintain such code, the author of said atrocities can expect to feel the full force of my wrath.  

Never silently discard the results of an Exception. Not conditionally, not unconditionally. Even if the catch clause cleanly and completely handles the exception, for the sake of maintainability, make the Exception loggable. If you're creating a new Exception in your catch clause and throwing it, attach the original Exception in the "caused by" part of the new Exception.
 
reply
    Bookmark Topic Watch Topic
  • New Topic