This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Callable statement vs prepared statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Callable statement vs prepared statement" Watch "Callable statement vs prepared statement" New topic
Author

Callable statement vs prepared statement

fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Posts: 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
Posts: 10336

Not an ORM question. Moving...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

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]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Callable statement vs prepared statement
 
Similar Threads
PreparedStatement's executeQuery() returning resultset with no rows
How resultset is returned by stored procedure?
Problem Named Queries In Hibernate
Problem calling IN parameters Stored Procedure from Java
About Hibernate Support for StoredProcedure