title: How do you connect to H2 as a remote database instead of embedded mode using Spring Boot?
body: <p>I have this configuration under src/main/resources for my little Spring Boot application:</p>
  
  <pre><code>server.port = 8090
  spring.datasource.driverClassName = org.h2.Driver
  spring.datasource.url = jdbc:h2:file:~/stapler
  </code></pre>
  
  <p>I know this configuration is picked up properly, cause there is valid port number 8090 in application startup log. There is also a @PostConstruct initDb() method which creates and inserts data into 2 tables of that database:</p>
  
  <pre class="lang-java prettyprint-override"><code>package com.avk.stapler.init;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.jdbc.core.JdbcTemplate;
  
  import javax.annotation.PostConstruct;
  
  @SpringBootApplication
  public class DbInitializer {
      @Autowired
      private JdbcTemplate jdbcTemplate;
  
      public static void main(String[] args) {
          SpringApplication.run(DbInitializer.class, args);
      }
  
      @PostConstruct
      private void initDb() {
          System.out.println("Creating table employees");
          jdbcTemplate.execute("drop table employees if exists");
          jdbcTemplate.execute("create table employees(id serial, name varchar(255), surname varchar(255))");
          jdbcTemplate.execute("insert into employees(name, surname) values('Jan', 'Kowalski')");
          jdbcTemplate.execute("insert into employees(name, surname) values('Stefan', 'Nowak')");
  
  
          System.out.println("Creating table allocations");
          jdbcTemplate.execute("drop table allocations if exists");
          jdbcTemplate.execute("create table allocations(id serial, week int, year int, shift int, employee_id bigint)");
          jdbcTemplate.execute("insert into allocations(week, year, shift, employee_id) values(29, 2015, 1, 1)");
          jdbcTemplate.execute("insert into allocations(week, year, shift, employee_id) values(28, 2015, 2, 1)");
          jdbcTemplate.execute("insert into allocations(week, year, shift, employee_id) values(29, 2015, 3, 2)");
          jdbcTemplate.execute("insert into allocations(week, year, shift, employee_id) values(28, 2015, 2, 2)");
      }
  }
  </code></pre>
  
  <p>I can see this logged on startup, I don't think there are more logs regarding DB:</p>
  
  <pre><code>2015-09-30 22:41:22.948  INFO 2832 --- [           main] o.s.j.d.e.EmbeddedDatabaseFactory        : Creating embedded database 'testdb'
  Creating table employees
  Creating table allocations
  </code></pre>
  
  <p>And as a result of above, I'd like to see a "stapler.h2.db" file in my home directory, which is not the case. What should be changed here for the DB file to appear?</p>