Unanswered: code difference for PreparedStatement and Statement
We know preparedStatement in JDBC has performance benefit for frequently called queries because preparedStatement will be compiled and cached on the server.
My question is do we need to avoid multiple calls to create a preparedStatement or it will not matter because server can handle it by check the existing compiled result?
For example, I have a addNewCustomer() method which will be called each time a new customer is added.
1. Do I need to include the preparedStatement creation statements (the first two) inside this method or
2. I should put the first two statements in another method which only be called once at initiaizing stage?
option 2 make more sense to me but my concern is the Connection. If I have a connetion pool and the PreparedStatement is bound with the connection instance, how can I guarante the connection? or I shouldn't care of it at all.