title: How to retrieve column names from an in memory database?
body: <p>Here's the code that gives me headaches:</p>
  
  <pre><code>  public List&lt;String&gt; listColumnsForTable(String tableName) throws SQLException {
      List&lt;String&gt; columns = new ArrayList&lt;String&gt;();
      DatabaseMetaData metadata = _connection.getMetaData();
      ResultSet resultSet = metadata.getColumns(null, null, tableName, null);
      while (resultSet.next())
        columns.add(resultSet.getString("COLUMN_NAME"));
      return columns;
    }
  </code></pre>
  
  <p>This code <strong>works fine with SQL Server</strong> (I haven't checked with MySQL, Oracle or others), but I need to run some <strong>integration tests on an in memory database</strong>. All the databases I tried (h2, hsqldb and derby) <strong>fail</strong>.</p>
  
  <p>Here is <a href="https://github.com/sensui/InMemoryColumns" rel="nofollow"><strong>the link on github</strong></a>.</p>
  
  <p>If you want the <strong>full project</strong> (with tests for h2, hsqldb, derby and sql server) do the following:</p>
  
  <pre><code>git clone git://github.com/sensui/InMemoryColumns.git
  cd InMemoryColumns
  gradlew
  </code></pre>
  
  <p>All the dependencies will be automatically downloaded. If you want to check the library versions look in the <code>build.gradle</code> script.  </p>
  
  <p>Now import the project in your favorite IDE (eclipse or idea).  </p>
  
  <p>The tests are available in the <code>DatabaseMetadataCheckerTests</code> class (<code>canListColumnsForTable</code> and <code>canCheckIfColumnsExistInTable</code>).   </p>
  
  <p>Normally you shouldn't modify those. I have created <strong>4 test classes</strong> that provide connection details for each in memory database and you need to run those (the <code>DatabaseMetadataCheckerTests</code> is abstract so you don't run that).</p>
  
  <p><strong>NOTE:</strong>
  When/if you find a solution than the tests for that specific database <strong>will pass</strong>.
  You can easily try other databases like Oracle or MySQL just by extending the <code>DatabaseMetadataCheckerTests</code> class and providing the connection details (check the other tests).</p>
  
  <h2>Issue solved</h2>
  
  <p>The <strong>table names and column names</strong> should be in <strong>UPPERCASE</strong>. Check <a href="https://github.com/sensui/InMemoryColumns/commit/5182aa1b6385ccd64023f50b7198cc9702510b66" rel="nofollow"><strong>this commit</strong></a> for details.</p>