This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes passing table names at runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "passing table names at runtime" Watch "passing table names at runtime" New topic

passing table names at runtime

Shahabuddin Syed

Joined: Oct 25, 2003
Posts: 5
the name of tables in the My database change at runtime so i want to pass the values of tables as parameters at runtime, i cannot do it with "PreparedStatement", is there any efficient way.
thanks in advance,
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Hi Shahabuddin,
As you have discovered, you cannot use the "?" parameter place-holders in a "PreparedStatement" for database table names (nor column names, for that matter), only for literal values (like strings, numbers, dates, etc.)
The only way is to build up the SQL string in your java class, for example (note: uncompiled and untested)

Good Luck,
Consider Paul's rocket mass heater.
subject: passing table names at runtime
Similar Threads
compile-time polymorphism
Table Design using Absolure or Relative
Netbeans doesn't show tables in SQLServer 2005
JPA different tables, same entity-type
Hibernate - Single Class to Multiple Tables