Table name as paramter to PreparedStatement?
Can a table name be provided as a parameter to a Prepared Statement? We are using Oracle 10 and have data stored in different schemas. The tables in each schema are identical, but depending on the customer querying the database we need to view the data in one schema or another. Follows is the code we are using:
Connection con = session.connection();
PreparedStatement stmt = con.prepareStatement("select * from ?");
stmt.setString(1, customerSchema+".visit");
ResultSet rs = stmt.executeQuery();
and then we get the exception:
ORA-00903: invalid table name
Is what I am trying to do possible without reverting to changing the Prepared Statement call to:
PreparedStatement stmt = con.prepareStatement("select * from " + customerSchema+".visit");
The reason I would avoid the above code, is because we want to use Hibernate and use the mapping file for SQL statement, but the problem I have is SQL/JDBC focused, since Hibernate can't do something that JDBC can't do.
BTW I am dealing with a legacy database, so while it would be nice to correct the database design, there is too much already in place to do so at this time.

