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.

Any expert can explain this to me? thanks,

public int addNewCustomer(Customer customer){

try {
String sql = createPrepStmntStrInsertIntoCustomer();
prepStmntInsertCustomer = m_conn.prepareStatement(sql);

fillPrepStmntInsertIntoCustomer(prepStmntInsertCus tomer, customer);
} catch (SQLException e) {
// TODO Auto-generated catch block

return custId;