aspose file tools*
The moose likes JDBC and the fly likes executeUpdate() return Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "executeUpdate() return" Watch "executeUpdate() return" New topic
Author

executeUpdate() return

sumit gandhi
Greenhorn

Joined: Aug 13, 2007
Posts: 2
Hi,
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) {
<Success>}
else {
<throw exception>
}
??? in above condition should be >,>= . Please respond.}
Medha Jhunjhunwala
Greenhorn

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.

http://java.sun.com/j2se/1.4.2/docs/api/java/sql/PreparedStatement.html#executeUpdate()

-Medha
Abhishek Asthana
Ranch Hand

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

Joined: Aug 13, 2007
Posts: 2
Thanks Medha and Abhishek for your responses.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: executeUpdate() return