Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is pre-compiled SQL statement? [duplicate]

PreparedStatement is a precompiled statement so it will increase jdbc performance at runtime but still confused about

  1. What is precompiled SQL Statement? What it does?
  2. Why precompiled statement is faster than usual SQL Statement?
like image 424
Sasikumar Murugesan Avatar asked Dec 15 '22 14:12

Sasikumar Murugesan


1 Answers

The following steps are used by any database while running an SQL query:

  1. Convert given SQL query into DB format
  2. Check for syntax
  3. Check for semantics
  4. Prepare execution plan
  5. Set the run-time values into the query
  6. Run the query and fetch the output

In case of Statement interface all above 6 steps need to be followed for each query execution. However, in case of PreparedStatement interface steps 1 to 4 will be done only once and steps 5 & 6 will be repeated for each execution of the query. This makes the PreparedStatement faster.

Hope this answers your question...

like image 133
Pavan Kumar K Avatar answered Jan 02 '23 07:01

Pavan Kumar K