# prepared statements in MySQL

**URL:** <https://forums.percona.com/t/prepared-statements-in-mysql/470>\
**Category:** Other MySQL® Questions\
**Created:** [September 28, 2007, 1:32pm UTC](https://forums.percona.com/t/prepared-statements-in-mysql/470 "2007-09-28T13:32:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikec](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@mikec](https://forums.percona.com/u/mikec)\
**Post date:** [September 28, 2007, 1:32pm UTC](https://forums.percona.com/t/prepared-statements-in-mysql/470/1 "2007-09-28T13:32:02Z")

</div>

Is there any advantage to using prepared statements in Java for DML in the following  
scenario:

get a connection, prepare a statement, substitute the variable value, execute, close the  
statement - repeat this process over and over.

Don’t you need to not close so that you don’t have to re-prepare the statement  
in order to gain any performance advantage?

---

<div class="post-metadata">

**Author:** ![sterin](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@sterin](https://forums.percona.com/u/sterin)\
**Post date:** [September 30, 2007, 6:46pm UTC](https://forums.percona.com/t/prepared-statements-in-mysql/470/2 "2007-09-30T18:46:40Z")

</div>

That is correct, you need to hold the handle for the prepared statement and re-execute it with just different values each time.

prepare statementLOOP: execute statement with different valuesEND:close statement.
