Forums Register Login

executeUpdate() return Value

+Pie Number of slices to send: Send
Hi All,

This method returns an int which is number of rows affected by the query, otherwise will throw an exception. This is how the method behaves right? Having some doubt about any other posibilities. I'm handling a DBConnection class which encapsulate the JDBC API methods.

Thanks in advance,
+Pie Number of slices to send: Send
 

Originally posted by Vijitha Kumara:
This method returns an int which is number of rows affected by the query, otherwise will throw an exception. This is how the method behaves right?


Yes. By definition a method either returns a value (or void) or throws an exception. Do keep in mind that it might return the number zero if no rows are updated.

If you describe what scenario you are thinking of, people may give a more useful answer.
+Pie Number of slices to send: Send
Thanks Jeanne. I'm just checking a code some other developer has done for the DBConncetion I mentioned above. One method would be like this. Here when the connection is created it sets the autocommit to false. This method has few problems as I see. Please asume all the variables are properly defined and initialized. (stmt--> Statement).


Consider an Insert Statement (one for the master record and few records for breakdown table)

The problem I see is if the calling method has some other queries to be executed(say records for the breakdown table) after this call, if this throws an exception (which it handles itself) other queries may still get executed, which may not what the developer wants it to do. Any comments would really appretiated.
+Pie Number of slices to send: Send
 

Originally posted by Vijitha Kumara:
The problem I see is if the calling method has some other queries to be executed(say records for the breakdown table) after this call, if this throws an exception (which it handles itself) other queries may still get executed, which may not what the developer wants it to do. Any comments would really appretiated.


That would depend on whether the caller did anything with the false return value. It's a bit odd to use a boolean rather than an exception though.
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 24128 times.
Similar Threads
simple web browser in java
NX: When should I throw DuplicateKeyException?
How a character save in 2 bytes in Java?
java.lang.exception
Formatting decimals
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:07:54.