
What is the difference between statement and a prepared statement?

A Statement is usually parsed and executed each time it is submitted to the database. A PreparedStatement may be parsed once and executed repeatedly with different parameters.
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.

*There are four steps for the execution of query :such as Query is parsed,Query is compile,Query is optimizedand Query is excuted.
In case of statement interface these four steps are performed ,each time when query is submitted for execution.But in case of prepared statement first three steps are performed only once, when the query in initially submitted.Only the last step is performed each time query is submitted(in subsequence submissions),i.e if same query is submitted to be execute with different values multiple times then prepared statement interface provides better perfromance as compared to statement interface.*
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.