What is prepared statement in jdbc

what is prepared statement in jdbc

Prepared Statement vs Callable Statement

Post by: Nupur Gupta, Ranch Hand

on Apr 13, 2007 08:25:00

Hi,

What is the difference between a PreparedStatement and a CallableStatement?

I have searched a lot on the internet for it, and all the replies are confusing, contradictory.

This is what I have gleaned so far -

Prepared statement is a set of SQL queries(or a call to a stored procedure). This is precompiled on the database. One can call it again and again, specifying different paramaters each time.

Callable Statement is also a call to a stoerd procedure, but it is permanently precompiled, and is called again and again. passing different parameters.

So it seems to be the difference between 'precompiled' and 'permanently precompiled'. What does this mean? Are they not both a set of SQL queries, ie a stored procedure? Further I read that a Callable Statement is a subclass of a Prepared statement. so the plot just gets thicker. Hmm..

Help much appreciated.

Post by: Shailesh Chandra, Ranch Hand

on Apr 14, 2007 10:29:00

At the top level you can go by this thought

  • Prepared Statement

    Instances of PreparedStatement contain an SQL statement that has already been compiled. This is what makes a statement "prepared"

    Because PreparedStatement objects are precompiled, their execution can be faster than that of Statement objects.

    The prepared statement is used to execute sql queries

  • Callable Statement

    A CallableStatement object provides a way to call stored procedures in a

    standard way for all RDBMSs. A stored procedure is stored in a database; the call to the stored procedure is what a CallableStatement object contains.

    call to a stoerd procedure, but it is permanently precompiled

    JavaOracleSpringpurple mooseage

    Thanks,

    Shailesh

    Post by: Nupur Gupta, Ranch Hand

    on Apr 14, 2007 11:03:00

    Thanks a lot for your help Shailesh.But I really dont understand.

    "Instances of PreparedStatement contain an SQL statement that has already been compiled. This is what makes a statement "prepared" "

    "A CallableStatement object provides a way to call stored procedures in a standard way for all RDBMSs. A stored procedure is stored in a database; the call to the stored procedure is what a CallableStatement object contains."

    So both of them seem to be the same thing. Both of them seem to consist of SQL statements which are already compiled, and hence faster to execute. What is the difference?

    Would much appreciate any feedback.

    Post by: Carol Enderlin, Ranch Hand

    on Apr 14, 2007 15:09:00

    A stored procedure is in the database (permanently compiled) and may be called by a CallableStatment.

    A PreparedStatement compiles a query in your java code. It may be re-used, therefore it is pre-compiled. compiled before you use it. Perhaps more important these days, you can use question marks (?) in your query to represent values you need to set using PreparedStatements (cannot do that with plain Statement).

    Source: www.coderanch.com

    Category: Forex

    Similar articles: