Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the difference between executeUpdate and execute?

 
thomas davis
Ranch Hand
Posts: 207
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between executeUpdate and execute?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between executeUpdate and execute?

Well, execute() can be used to execute any kind of an SQL statement (i.e. SELECT, UPDATE, INSERT, DELETE) while executeUpdate() can only be used with UPDATE, INSERT or DELETE.
 
thomas davis
Ranch Hand
Posts: 207
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the return type of execute ?
What is the return type of executeUpdate?
If I am deleting records from two table which have primary-foreign key relationship,then if something happened to the first query ,how can I retrieve message and tell the user that some error(primary key violation) occured during deletion ? Cn I use return type of executeUpdate ?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the return type of execute?
What is the return type of executeUpdate?

execute() returns a boolean indicating simple success/failure for the operation you tried to execute. executeUpdate() returns the number of successful record updates (e.g. "2" for "2 rows were deleted").
If I am deleting records from two table which have primary-foreign key relationship,then if something happened to the first query ,how can I retrieve message and tell the user that some error(primary key violation) occured during deletion ? Cn I use return type of executeUpdate ?

No, you can't use the return type of executeUpdate() to tell any specifics of the failure because the return type indicates only successful updates. Errors such as a primary key violation are indicated by the JDBC driver via an SQLException. You can get the database specific error code with SQLException.getErrorCode().
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic