Skip to main content

Sharing a global Statement vs creating a new one each time

1 reply [Last post]
Joined: 2006-06-20


I've got a situation where I have 1 class that does a bunch of DB operations. I'm stuck between having 1 Statement object that is shared with all the methods in that class. And with having each method create a new Statement object whenever it needs to do something.

For me it's good to have statement creation on demand as each method can call on others and I won't have ResultSet problems if both are executing queries.

Now the question... what's the performance loss from creating new Statements each time I need it verses using just 1 ?

Thanks for any help or links to sites :)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-01-07

This really depends on the JDBC driver used.
Why not create a pool, where you can request a free Statement if you need one, and return it when you're done using it?

- Clemens