Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Updating several consecutive columns in an Apache derby database  RSS feed

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • 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: 5041
134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "seems to falter" mean? TellTheDetails
 
Bob Matthews
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • 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: 5041
134
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following code appears further down..................

 
Marshal
Posts: 61741
193
  • Mark post as helpful
  • send pies
  • 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: 5041
134
  • Mark post as helpful
  • send pies
  • 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: 5446
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
apologies.......................

 
Bob Matthews
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • 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: 5144
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • 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: 5041
134
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 10 coding was in error - requires string concatination

Thanks

Bob M
 
Carey Brown
Saloon Keeper
Posts: 5144
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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: 5446
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • 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: 5446
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a prepared statement.
 
Bartender
Posts: 19984
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!