Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the Advantage Of Prepared Statement Over Statement

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • 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)
 
Neelima Garimella
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prepared Statement: To Precompile and then execute statement
Statement: Statement has to be compiled everytime.
 
Sandeep Jain
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • 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
 
alka_duggal
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
 
rasit fidanov
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Link to the other topic Rasit mentioned. Please direct comments there.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic