IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JDBC
 
RSS feed
 
New topic
Author

Callable statement vs prepared statement

fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Messages: 85

Callable is used to call stored procedures specifically.
We can call stored procedures using Prepared Statement also using sql string as
<code>
{call sp_name (?,?)}
</code>

Why should we choose one over the other? What are the advantages enjoyed?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Messages: 8544

Not an ORM question. Moving...

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jeanne Boyarsky
internet detective
Sheriff

Joined: May 26, 2003
Messages: 17194

Originally posted by fahad siddiqui:
Why should we choose one over the other? What are the advantages enjoyed?

If you have a stored procedure, you should use CallableStatement. A PreparedStatement is not guaranteed to work across all databases and drivers. This makes your code less robust. While you probably aren't changing databases with stored procs, you are likely to upgrade the driver.

Oracle fixed a bug in getDate() in Oracle 10 which caused legacy code to break that was relying on a side effect. If you follow the spec (or intent of the API), you protect your code against future changes.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]

"The set strikes me as something like the set of potatoes, radishes, farming, and lunch. " - a colleague's way of comparing both overlapping and disparate groups. made me laugh and thought of the ranch
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JDBC
 
RSS feed
 
New topic
The most intelligent Java IDE