This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes To delete a record  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "To delete a record  " Watch "To delete a record  " New topic
Author

To delete a record

Rajesh Pathak
Ranch Hand

Joined: Aug 15, 2002
Posts: 56
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?


Rajesh(Bangalore,India)<br />SCJP2, SCWCD, SCEA, IBM-XML, UML-OOAD, IBM-Enterprise Connectivity with J2EE.
Kevin Mukhar
Ranch Hand

Joined: Nov 28, 2000
Posts: 83
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

Joined: Aug 15, 2002
Posts: 56
Thanks a lot Kevin for a explanation.
 
GeeCON Prague 2014
 
subject: To delete a record