Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executeUpdate() return

 
sumit gandhi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you can make use of 'execute' in place of executeUpdate.
 
sumit gandhi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Medha and Abhishek for your responses.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic