title: How do I create a H2 database inside a java project in Eclipse?
body: <p>I want to create an embedded H2 database in my simple java project in Eclipse. How do I do this programatically and package the db inside my code ? I tried a <a href="https://stackoverflow.com/questions/154636/embedding-the-java-h2-database-programmatically">SO post</a> for this 
  and got an error in my code.</p>
  
  <p>Code - </p>
  
  <pre><code>public static void main(String[]args){
  
      JdbcDataSource ds = new JdbcDataSource();
      ds.setURL("jdbc:h2:˜/test");
      ds.setUser("sa");
      ds.setPassword("sa");
      try {
          Connection conn = ds.getConnection();
      } catch (SQLException e) {
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>Error - </p>
  
  <pre><code>org.h2.jdbc.JdbcSQLException: A file path that is implicitly relative to the 
  current working directory is not allowed in the database URL "jdbc:h2:˜/test". 
  Use an absolute path, ~/name, ./name, or the baseDir setting instead. [90011-181]
      at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
      at org.h2.message.DbException.get(DbException.java:179)
      at org.h2.message.DbException.get(DbException.java:155)
      at org.h2.engine.ConnectionInfo.getName(ConnectionInfo.java:398)
      at org.h2.engine.Engine.openSession(Engine.java:45)
      at org.h2.engine.Engine.openSession(Engine.java:167)
      at org.h2.engine.Engine.createSessionAndValidate(Engine.java:145)
      at org.h2.engine.Engine.createSession(Engine.java:128)
      at org.h2.engine.Engine.createSession(Engine.java:26)
      at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:347)
      at org.h2.jdbc.JdbcConnection.&lt;init&gt;(JdbcConnection.java:108)
      at org.h2.jdbc.JdbcConnection.&lt;init&gt;(JdbcConnection.java:92)
      at org.h2.Driver.connect(Driver.java:72)
      at org.h2.jdbcx.JdbcDataSource.getJdbcConnection(JdbcDataSource.java:190)
      at org.h2.jdbcx.JdbcDataSource.getConnection(JdbcDataSource.java:161)
      at MyCode.main(MyCode.java:8)
  </code></pre>
  
  <p>I saw this link - <a href="https://groups.google.com/forum/#!msg/h2-database/SlSwte0DLSU/eWj0UaejdkEJ" rel="nofollow noreferrer">https://groups.google.com/forum/#!msg/h2-database/SlSwte0DLSU/eWj0UaejdkEJ</a> and <a href="https://stackoverflow.com/questions/6397716/where-are-my-h2-database-files">Where are my H2 database files?</a>. Its not clear how I can get the exact path to test database on my windows pc.</p>
  
  <p>How do I first access the test database and then create another database inside my java project ?</p>
  
  <p>Thank you.</p>