• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

What is the difference between executeUpdate and execute?

 
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between executeUpdate and execute?
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
reply
    Bookmark Topic Watch Topic
  • New Topic