• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

To delete a record

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to write a JDBC code which will remove a record from the database. Which method should I use should I use executeUpdate or execute? Does any of them should have advantage over other?
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rajesh Pathak:
I want to write a JDBC code which will remove a record from the database. Which method should I use should I use executeUpdate or execute? Does any of them should have advantage over other?


Use executeUpdate(). While execute() will work, it is meant for situations where you do not know whether the SQL will return a ResultSet or a count of rows affected or possible both. This might happen if you let a user enter arbitrary SQL, or when you are calling a function that returns both result sets and a count of affected rows.
So, the advantage that execute() has over executeUpdate() is that you can use it in any situation. The disadvantage is that if you don't know the return value, you have to call extra methods to determine whether you have a ResultSet or a count. Thus, it's a little more straightforward to use executeQuery() when you know that you will get a ResultSet from an SQL statement, and executeUpdate() when you know the SQL will return a count.
K Mukhar
http://home.earthlink.net/~kmukhar
 
Rajesh Pathak
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Kevin for a explanation.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic