Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes when to use callable 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 "when to use callable statement???" Watch "when to use callable statement???" New topic
Author

when to use callable statement???

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 980
    
    2
i need to design few servlets and jsp's for login and register of user.
i want to know one thing, should i use callable statement for this, i tried to read it via google, but failed to get anything for "when to use callable statement".
i m doing this only for my learning exercise.
most of the times i used statement and prepared statement for this, but now i think to use callable statement just for learning, should i use, any good reason why to use??

Thank You....
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

You'll use CallableStatement when you're invoking a stored function which returns a value, or stored function or procedure which uses OUT parameters. The CallableStatement interface provides methods to register the output parameters with their proper type and obtain their value after execution.

Therefore, if you want to practice the use of this interface, you need to have a stored procedure or function to call. I'd suggest starting by reading the CallableStatement documentation, or even better the corresponding sections of an JDBC tutorial.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 980
    
    2
Thank you...
but for login and registrations, does callable statements has any advantage over prepared statement, should i use??
although prepared statement prevent from sql injuctions and all.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

No, there is no advantage as far as I know. Both of these handle bind variables (the parameters) in the same way and therefore provide the exact same protection from SQL injection attacks. (That is, when you use them correctly. It is still possible to be subject to SQL injection if you use PreparedStatement or CallableStatement and just stuff in parameters by String concatenation.)
 
Consider Paul's rocket mass heater.
 
subject: when to use callable statement???
 
Similar Threads
Prepared Statement Vs. Callable Statement
Function in Callable Statement
Rangarajan Balasubramanian
Prepared Vs Callable statements
Callable and executor Framework