title: Can't reach temp table with using prepared statement for second time
body: <p>I am using temporary tables inside my code in order to [some long sequnce of reasons here] in SQL Server, Java. I was executing my sql queries with using Stament object in java. However, recently I decided to use PreparedStatement in order to avoid injection thing.</p>
  
  <p>My problem is when create a temporary table with using PreparedStatement, I can not reach it with the same prepared statement again. Here is a simple illustration:</p>
  
  <pre><code>sql = "select * into #someTable from (select someColumns from someOtherTable where smth = ? and smth2 = ?)"
  PreparedStatement preparedStatement = conn.prepareStatement(sql);
  for(int i=0; i&lt;parameters.size(); i++){
     preparedStatement.setString(i+1, parameters.get(i).toString());
  }
  
  this.rs = preparedStatement.executeQuery();
  </code></pre>
  
  <p>Until here, it is ok. After getting ResultSet and doing something with it, or without getting a resultSet just for <code>preparedStatement.execute()</code> does not makes difference, I can not reach the #someTable object again.  </p>
  
  <pre><code>sql = "select count(*) from #someTable"
  preparedStatement = conn.prepareStatement(sql);
  this.rs = preparedStatement.executeQuery();
  </code></pre>
  
  <p>Here <code>this.rs = preparedStatement.executeQuery();</code> part gives <code>'Invalid object name #someTable'</code>. I am doing all of the things above with using one Connection object only and without closing or reopening it. I need to use that temp table again. Is there any way to create temp table with PreparedStatement object in java and reuse this temp table again and again? Regards,</p>