Hi Harald, I would not recommend keeping a DBCommand for longer than the current context. Creating a command object is cheap and it does not influence the prepared statement caching in any way.
However I would recommend to reuse the DBCommand and modify the param values directly in cases where you locally execute the same statement multiple times with varying param values as indicated in the example. On the other side, there is nothing that restricts you from reusing a DBCommand object. You might even store it on session scope. However be aware that modification of the command object is not thread safe. Regards Rainer > from: Harald Kirsch [mailto:[email protected]] > to: [email protected] > re: prepared statements best practices > > Hi there, > > what are considered best practices for reusing DBCommand objects, in > particular when they contain prepared statements or, rather, had > addParam() called. Is it recommended to reuse the objects and just change > the parameters? > > In the SampleAdvApp only the parameters are changed. But I would like to > be sure that this is not only done because the object is on the stack anyway. > What if I would need to store it, typically in a ThreadLocal. Is that worth > the > effort given that I am feeding 40 million rows into the DB? > > Thanks, > Harald. > > -- > Harald Kirsch > Raytion GmbH
