It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes executeUpdate() return Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "executeUpdate() return" Watch "executeUpdate() return" New topic

executeUpdate() return

sumit gandhi

Joined: Aug 13, 2007
Posts: 2
Need your help on this one.I am using PreparedStatment to update the database records.Now, I want to throw Application exception on the basis of returned value from executeUpdate(). What should be the condition to throw exception?
int intReturn = pstmtUpdate.executeUpdate();
if (intReturn ??? 0) {
else {
<throw exception>
??? in above condition should be >,>= . Please respond.}
Medha Jhunjhunwala

Joined: Sep 06, 2007
Posts: 9
intReturn will have the number of rows updated. So, if you think that updation of 0 rows is an exception, then use intReturn > 0 as success condition.

Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
Maybe you can make use of 'execute' in place of executeUpdate.
sumit gandhi

Joined: Aug 13, 2007
Posts: 2
Thanks Medha and Abhishek for your responses.
I agree. Here's the link:
subject: executeUpdate() return
It's not a secret anymore!