title: calling derby (java db) 'show tables' from jdbc
body: <p>I need to enumerate the tables in a Derby (aka Java DB) database using JDBC in a Java program.  All I am aware of for doing this is the SHOW TABLES command.  </p>
  
  <p>I first tried with something similar to this...</p>
  
  <pre><code>String strConnectionURL = "jdbc:derby:/path/to/derby/database;create=false";
  Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
  Connection connection = DriverManager.getConnection(strConnectionURL);
  Statement statement = connection.createStatement();
  boolean boResult = statement.execute("SHOW TABLES");
  if (boResult) {
      System.out.println("yay!");
  }
  </code></pre>
  
  <p>...but that throws an exception: </p>
  
  <pre><code>java.sql.SQLSyntaxErrorException: Syntax error: Encountered "SHOW" at line 1, column 1.
  </code></pre>
  
  <p>So next I thought maybe I needed to use a CallableStatement so I tried this...</p>
  
  <pre><code>String strConnectionURL = "jdbc:derby:/path/to/derby/db;create=false";
  Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
  Connection connection = DriverManager.getConnection(strConnectionURL);
  CallableStatement statement = connection.prepareCall("SHOW TABLES");
  boolean boResult = statement.execute();
  if (boResult) {
      System.out.println("yippee!");
  }
  </code></pre>
  
  <p>...but that throws the same exception:</p>
  
  <pre><code>java.sql.SQLSyntaxErrorException: Syntax error: Encountered "SHOW" at line 1, column 1.
  </code></pre>
  
  <p>So, can anyone help me enumerate the tables in my Derby (Java DB) database from JDBC? </p>
  
  <p><b>EDIT</b>:  I'm looking around and starting to get a feeling this may be a general JDBC question.  In other words, one could/would enumerate all a db's tables with the DatabaseMetaData object that can be retrieved from the Connection object.  Looking into that (and looking forward to responses)...</p>
  
  <p><b>EDIT 2</b>: I found a pure JDBC solution, but am still happy to hear alternatives...</p>
  
  <pre><code>String strConnectionURL = "jdbc:derby:/path/to/db;create=false";
  Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
  Connection connection = DriverManager.getConnection(strConnectionURL);
  DatabaseMetaData dbmd = connection.getMetaData();
  ResultSet resultSet = dbmd.getTables(null, null, null, null);
  while (resultSet.next()) {
      String strTableName = resultSet.getString("TABLE_NAME");
      System.out.println("TABLE_NAME is " + strTableName);
  }
  </code></pre>