The Artima Developer Community
Sponsored Link

Web Services Forum
JDBC

1 reply on 1 page. Most recent reply: Mar 23, 2004 11:11 PM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
anamika

Posts: 11
Nickname: anamika
Registered: Feb, 2004

JDBC Posted: Mar 14, 2004 8:13 AM
Reply to this message Reply
Advertisement
hi,
can you tell me what is the differece between a prepare stament and a statement in JDBC connection


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: JDBC Posted: Mar 23, 2004 11:11 PM
Reply to this message Reply
Statement prepares and executes the query plan
each time, while PreparedStatement prepares the query plan once and then reuses the
query plan. Preparing a statement is also referred to as precompiling a statement.
If that were the whole story, then PreparedStatement would always be the statement
of choice, and youwou ld avoid Statement objects completely. But itÂ’s not quite the
whole story. Statement has optimizations that the database can apply; mainly, the
database knows that the Statement plan is executed immediately and thrown away.
So the database handles Statement queries differently from PreparedStatements.
Statement queries can be prepared and executed in one swoop, using the state of the
database at the time, without allocating resources to keeping the plan around.
PreparedStatements, on the other hand, need to allocate database resources to store
and maintain the query plan and to ensure that the query plan is not invalidated by
changes to the database. For example, the query plan would need to be updated or
re-created in the case of some types of changes to the database, depending on how
detailed the query plan is.

These are the two links you should go

http://otn.oracle.com/oramag/books/oreilly/ch16_jdbc_shirazi.pdf
http://www.jguru.com/faq/view.jsp?EID=693


Short answer:

The PreparedStatement is a slightly more powerful version of a Statement, and should always be at least as quick and easy to handle as a Statement.
The PreparedStatement may be parametrized.

Longer answer: Most relational databases handles a JDBC / SQL query in four steps:

Parse the incoming SQL query
Compile the SQL query
Plan/optimize the data acquisition path
Execute the optimized query / acquire and return data


A Statement will always proceed through the four steps above for each SQL query sent to the database. A PreparedStatement pre-executes steps (1) - (3) in the execution process above. Thus, when creating a PreparedStatement some pre-optimization is performed immediately. The effect is to lessen the load on the database engine at execution time.

Flat View: This topic has 1 reply on 1 page
Topic: SOAP:The most simple example Previous Topic   Next Topic Topic: Connection reset by peer: JVM_recv in socket input stream read

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use