title: Passing table name as parameter of prepared statement
body: <p>I'm trying to learn how to use MySQL with Java and as the title says, I'm having problems with prepared statements. </p>
  
  <p>I have a MySQL table named temp which contains the values (output directly from MySQL console):</p>
  
  <pre><code>mysql&gt; select * from temp;
  +------+-----------------------------------------------+
  | id   | value                                         |
  +------+-----------------------------------------------+
  |    1 | this is a first item                          |
  |    2 | this is the second item                       |
  |    3 | This is the third item and slightly redundant |
  +------+-----------------------------------------------+
  3 rows in set (0.00 sec)
  </code></pre>
  
  <p>In Java I'm accessing the DB like this:</p>
  
  <pre><code>stmt = conn.prepareStatment("select * from ?");
  stmt.setString(1,"temp");
  ResultSet rs = stmt.executeQuery(); //This method call throws the exception
  </code></pre>
  
  <p><code>stmt.toString</code> reveals: <code>select * from 'temp'</code>
  and the exception message is: <code>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''temp'' at line 1</code></p>
  
  <p>When I type <code>select * from 'temp'</code> (The output of <code>stmt.toString()</code>) directly into the MySQL console I get the exact same message. </p>
  
  <p>As you may have imagined, I'm planning on applying this concept to a JSP webpage, where the table name will be a HTTP GET parameter. So my question is: How do I bind the table name to the prepared statement and if it's not possible (which is the vibe I'm getting from similar questions for PHP), how would I sanitize input for the table name?</p>