Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

How can i view all tables

someba
2005-01-12
2014-01-19
  • someba
    someba
    2005-01-12

    Hi all,

    i am trying to read all table names from hsqldb. But when i tried to run "show table" query in java code, i got following error;

    java.sql.SQLException: Unexpected token: SHOW in statement [show]
        at org.hsqldb.jdbc.jdbcUtil.sqlException(Unknown Source)
        at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
        at org.hsqldb.jdbc.jdbcStatement.executeQuery(Unknown Source)
        at Test.query(Test.java:30)
        at Test.main(Test.java:70)

    some part of code is:
    Class.forName("org.hsqldb.jdbcDriver");
            conn = DriverManager.getConnection(
                    "jdbc:hsqldb:" + "192.168.x.x", "sa","");
    st = conn.createStatement(); // statement objects can be reused with
    rs = st.executeQuery("show tables");

    Do you have any idea to get table names from hsql db?

     
    • as a non-portable SQL query:

      select * from system_tables;

      //--

      As a portable jdbc routine (sorry if I get some parameters wrong here...read the specs):

      conn  = DriverManager.getConnection(...)
      dbmd = conn.getMetaData();
      rs      = dbmd.getTables(null, null, null);

      while (rs.next()) {
           System.out.println(rs.getString(3));
      }

      Also, take Blaine's interactive commandline org.hsqldb.util.SQLTool for a drive...I believe it provides commands to list the tables and to describe individual tables.

       
    • Jakob Jenkov
      Jakob Jenkov
      2005-01-12

      ... this isn't the help forum... but anyways.

      ... use the DatabaseMetaData available from a connection. I use it to list all tables in a database. It works nicely, and it's portable across JDBC compliant databases.

       
    • niche
      niche
      2005-03-22

      select * from system_tables