PreparedStatement

Posted by Steel Plume on Stack Overflow See other posts from Stack Overflow or by Steel Plume
Published on 2010-03-18T01:55:39Z Indexed on 2010/03/18 2:01 UTC
Read the original article Hit count: 531

Filed under:
|
|

Hello,

in the case of using PreparedStatement with a single common connection without any pool, can I recreate an instance for every dml/sql operation mantaining the power of prepared statements?

I mean:

for (int i=0; i<1000; i++) {
    PreparedStatement preparedStatement = connection.prepareStatement(sql);
    preparedStatement.setObject(1, someValue);
    preparedStatement.executeQuery();
    preparedStatement.close();
}

instead of:

PreparedStatement preparedStatement = connection.prepareStatement(sql);
for (int i=0; i<1000; i++) {
    preparedStatement.clearParameters();
    preparedStatement.setObject(1, someValue);
    preparedStatement.executeQuery();
}
preparedStatement.close();

my question arises by the fact that I want to put this code into a multithreaded environment, can you give me some advice? thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about jdbc