I am writing a software that requires me to prepare statements and set the values, execute the query and get results within a loop. This loop might have over 7,000 cycles. If I use simple statements rather than prepared statements, will the execution speed change greatly?
Here is the pseudo code
- Prepare Statements
- Get a list from somewhere
- Iterate through the list
- get the prepared statements and do some db querying and close the new resources like result sets.
- populate a map using the result and values from the initial list
Thanks.
Prepared statements are FASTER then non-prepared statements if you repeatedly use the same statement with multiple sets of data. I’m unaware of a situation where this is not true.
Once you’ve prepared a statement, its sent to the DB server which then only has to accept the data each time you call it — it doesn’t have to reprocess the statement every time you bind new data.
So the simple answer is:
No. They don’t.