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

Prepared statment

 
Nidhi Jain
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yesterday I faced one ques in interview....wats the diff. between prepared statement and simple statemnet,I said they are precomplied,then interviewer further asked me where the precomplied statement stroed so that we can call it again and again.

I said it's stored in Database...but he said no...

Please tell me the ans.I done some googling but didn't able to find the ans.

Thanks
 
Moayad Abu Jaber
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The different between the preparestatment can passed parameter as object to query. this actually resolved problem of concatenation query.
sometimes when you create query need to use the variable in your own application you need to concatenation this variable to query maybe this variable have character will be given error at runtime
such as single quotation, when put it in middle of query the compiler will be sense is the colsing the query.

see this site i find it talk about the preparedstatement in more detail :
http://www.javaworld.com/javaworld/jw-01-2002/jw-0125-overpower.html?page=1


I hope this information is helpful for you.
 
Nidhi Jain
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't understand wat you are saying........the link I browsed but didn't clear my doubts.
 
dhwani mathur
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nidhi!!


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

1)Parse the incoming SQL query
2)Compile the SQL query
3)Plan/optimize the data acquisition path
4)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.



Using prepare statement is less expensive 'coz, it pre executes the follwoing steps. Step 1 :Parse the incoming SQL query Step 2 :Compile the SQL query Step 3 :Plan/optimize the data acquisition path Where will be the pre executed steps stored, i.e) in Application server or in DataBaseServer


For more information go through this thread

Diff Between Statement and PreparedStatement


I hope it helps you to some extent.

SCJP(1.5),SCWCD(On the way....)
Dhwani:>Winning is not important but it is the only thing.
 
Nidhi Jain
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My doubt it where the precomplied statement stored?From where we can call it?
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nidhi Jain:
My doubt it where the precomplied statement stored?


have a look this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic