• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is the Advantage Of Prepared Statement Over Statement

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any Advantage of PreparedStatement(Pstmt) over The Statement(Other Than the Reusing the same Pstmt with changing the parameter values)
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prepared Statement: To Precompile and then execute statement
Statement: Statement has to be compiled everytime.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
Prepared Statements are precomiled ones , so they are not compiled everytime whereas with createStaement same is not the case.
As the prepared Statement are precomplied ones they are much faster and there by increase the efficiency .So it act as an advantage over the normal statement .

------------------
Sandeep Jain
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi actually this is not my reply but a question for u that what r the queries that we use with prepared statement.i mean when we use executeupdate(we can use insert,delete,update)what else how do we use
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have read about PreparedStatement and Statement's performances too.

and i wanted to see the difference byself.
So in oracle db i've created a table having 2 numbers and 1 varchar column.

And i ran an insert sql into test table in a loop of 5000 times.
and i measured the time with System.currentTimeMillis();

before and after the loop to demonstrate PreparedStatement had better performance.

I tested it several times.

At first Statement finished jobs with the 89 secs.

PreparedStatement finished with 49 seconds.

as i told i tested it several times.

then more and more Statement closed the difference of time
between PreparedStatement.

Can any body explain this stuation?

My friend That he doesnt understand any java but he knows oracle very well explained me that with "oracle forms" if an sql statement sent to db then it compiles it only for once and executes the compiled sql if asked for again...

Does oracle do some trick at db side to reduce the compilation time?

??
[ July 07, 2005: Message edited by: rasit fidanov ]
 
rasit fidanov
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry as i added my reply under this topic and could not see.I created a new topic.

And added some at the end too.
Can you read Statement vs. Preparedstatement topic?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Link to the other topic Rasit mentioned. Please direct comments there.
reply
    Bookmark Topic Watch Topic
  • New Topic