title: Springboot 2.3.1 dynamically update Jdbc template's schema in Multi-tenant environment
body: <p>My Project is on spring-boot-starter-parent - &quot;1.5.9.RELEASE&quot; and I'm migrating it to spring-boot-starter-parent - &quot;2.3.1.RELEASE&quot;.</p>
  <p>This is multi-tenant env application, where one database will have multiple schemas, and based on the tenant-id, execution switches between schemas.</p>
  <p>I had achieved this schema switching using <strong>SimpleNativeJdbcExtractor</strong> but in the latest Springboot version <strong>NativeJdbcExtractor</strong> is no longer available.</p>
  <p>Code snippet for the existing implementation:</p>
  <pre><code> @Bean
  @Scope(
          value = ConfigurableBeanFactory.SCOPE_PROTOTYPE,
          proxyMode = ScopedProxyMode.TARGET_CLASS)
  public JdbcTemplate jdbcTemplate() {
      JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
      SimpleNativeJdbcExtractor simpleNativeJdbcExtractor = new SimpleNativeJdbcExtractor() {
          @Override
          public Connection getNativeConnection(Connection con) throws SQLException {
              LOGGER.debug(&quot;Set schema for getNativeConnection &quot;+Utilities.getTenantId());
              con.setSchema(Utilities.getTenantId());
              return super.getNativeConnection(con);
          }
  
          @Override
          public Connection getNativeConnectionFromStatement(Statement stmt) throws SQLException {
              LOGGER.debug(&quot;Set schema for getNativeConnectionFromStatement &quot;+Utilities.getTenantId());
              Connection nativeConnectionFromStatement = super.getNativeConnectionFromStatement(stmt);
              nativeConnectionFromStatement.setSchema(Utilities.getTenantId());
              return nativeConnectionFromStatement;
          }
      };
  
      simpleNativeJdbcExtractor.setNativeConnectionNecessaryForNativeStatements(true);
      simpleNativeJdbcExtractor.setNativeConnectionNecessaryForNativePreparedStatements(true);
  
      jdbcTemplate.setNativeJdbcExtractor(simpleNativeJdbcExtractor);
      return jdbcTemplate;
  }
  </code></pre>
  <p>Here Utilities.getTenantId() ( Stored value in ThreadLocal) would give the schema name based on the REST request.</p>
  <p>Questions:</p>
  <ul>
  <li>What are the alternates to <strong>NativeJdbcExtractor</strong> so that schema can be dynamically changed for JdbcTemplate?</li>
  <li>Is there any other way, where while creating the JdbcTemplate bean I can set the schema based on the request.</li>
  </ul>
  <p>Any help, code snippet, or guidance to solve this issue is deeply appreciated.</p>
  <p>Thanks.</p>