This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: executeUpdate() return
 
Similar Threads
auto commit within JTS transaction
Throwing multiple exception
Unavailable Exception Problem
Custom if then else tags?
this is wot my codes like