This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Prepared Statements, parameterized table names? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Prepared Statements, parameterized table names?" Watch "Prepared Statements, parameterized table names?" New topic

Prepared Statements, parameterized table names?

chandana sapparapu
Ranch Hand

Joined: Sep 28, 2002
Posts: 63
I understand that using parameters for queries helps the DBMS to reuse optimization plans.
A query like
select * from x where y= ?

is better that "select * from x where y= 10"

My question is, is the optimization plan reusable for different tables..

like select * from ? where y=?.

Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Chandana,

The optimiser would have to generate a new query plan for each table. One reason for this is that different tables may have different indexes so the method of accessing the data may be different. Even if the indexes, etc. were all the same on different tables, the optimised query plan only provides a template for substitution of values.

The same query using different values can be executed the same way. The same query using a different table must be executed differently (i.e. on a different table! )

chandana sapparapu
Ranch Hand

Joined: Sep 28, 2002
Posts: 63
Hi Julian,
Thanks for the reply. I also had a feeling that it varies from table to table, but just wanted to confirm it. Thanks for the details .

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Prepared Statements, parameterized table names?
It's not a secret anymore!