Example usage for java.sql DatabaseMetaData getTableTypes

List of usage examples for java.sql DatabaseMetaData getTableTypes

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData getTableTypes.

Prototype

ResultSet getTableTypes() throws SQLException;

Source Link

Document

Retrieves the table types available in this database.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getHSQLConnection();
    System.out.println("Got Connection.");
    Statement st = conn.createStatement();
    st.executeUpdate("create table survey (id int,name varchar);");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");

    ResultSet rs = null;/*  w ww.  jav a  2 s  .c  om*/
    DatabaseMetaData meta = conn.getMetaData();
    rs = meta.getTableTypes();

    while (rs.next()) {
        String tableType = rs.getString(1);
        System.out.println("tableType=" + tableType);
    }

    st.close();
    conn.close();
}

From source file:TableTypes.java

public static void main(String args[]) {

    String url = "jdbc:mySubprotocol:myDataSource";
    Connection con;/* www.  ja v  a  2  s .co m*/

    try {
        Class.forName("myDriver.ClassName");

    } catch (java.lang.ClassNotFoundException e) {
        System.err.print("ClassNotFoundException: ");
        System.err.println(e.getMessage());
    }

    try {
        con = DriverManager.getConnection(url, "myLogin", "myPassword");

        DatabaseMetaData dbmd = con.getMetaData();
        String dbmsName = dbmd.getDatabaseProductName();
        ResultSet rs = dbmd.getTableTypes();
        System.out.print("The following types of tables are ");
        System.out.println("available in " + dbmsName + ":  ");

        while (rs.next()) {
            String tableType = rs.getString("TABLE_TYPE");
            System.out.println("    " + tableType);
        }

        rs.close();
        con.close();

    } catch (SQLException ex) {
        System.err.print("SQLException: ");
        System.err.println(ex.getMessage());
    }
}

From source file:Main.java

public static void main(String[] argv) {
    Connection connection = null;
    Statement statement;//from  ww w.  ja  va 2 s . c  o m
    ResultSet rs;
    try {
        Context ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/AccountsDB");
        connection = ds.getConnection();

        DatabaseMetaData md = connection.getMetaData();
        statement = connection.createStatement();

        System.out.println("getURL() - " + md.getURL());
        System.out.println("getUserName() - " + md.getUserName());
        System.out.println("getDatabaseProductVersion - " + md.getDatabaseProductVersion());
        System.out.println("getDriverMajorVersion - " + md.getDriverMajorVersion());
        System.out.println("getDriverMinorVersion - " + md.getDriverMinorVersion());
        System.out.println("nullAreSortedHigh - " + md.nullsAreSortedHigh());

        System.out.println("<H1>Feature Support</H1>");
        System.out.println(
                "supportsAlterTableWithDropColumn - " + md.supportsAlterTableWithDropColumn() + "<BR>");
        System.out.println("supportsBatchUpdates - " + md.supportsBatchUpdates());
        System.out.println("supportsTableCorrelationNames - " + md.supportsTableCorrelationNames());
        System.out.println("supportsPositionedDelete - " + md.supportsPositionedDelete());
        System.out.println("supportsFullOuterJoins - " + md.supportsFullOuterJoins());
        System.out.println("supportsStoredProcedures - " + md.supportsStoredProcedures());
        System.out.println("supportsMixedCaseQuotedIdentifiers - " + md.supportsMixedCaseQuotedIdentifiers());
        System.out.println("supportsANSI92EntryLevelSQL - " + md.supportsANSI92EntryLevelSQL());
        System.out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar());
        System.out.println("getMaxRowSize - " + md.getMaxRowSize());
        System.out.println("getMaxStatementLength - " + md.getMaxStatementLength());
        System.out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect());
        System.out.println("getMaxConnections - " + md.getMaxConnections());
        System.out.println("getMaxCharLiteralLength - " + md.getMaxCharLiteralLength());

        System.out.println("getTableTypes()");
        rs = md.getTableTypes();
        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
        System.out.println("getTables()");
        rs = md.getTables("accounts", "", "%", new String[0]);
        while (rs.next()) {
            System.out.println(rs.getString("TABLE_NAME"));
        }
        System.out.println("Transaction Support");
        System.out.println("getDefaultTransactionIsolation() - " + md.getDefaultTransactionIsolation());
        System.out
                .println("dataDefinitionIgnoredInTransactions() - " + md.dataDefinitionIgnoredInTransactions());

        System.out.println("General Source Information");
        System.out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect());
        System.out.println("getMaxColumnsInTable - " + md.getMaxColumnsInTable());
        System.out.println("getTimeDateFunctions - " + md.getTimeDateFunctions());
        System.out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar());

        System.out.println("getTypeInfo()");
        rs = md.getTypeInfo();
        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.alifi.jgenerator.spring.SpringGeneratorFactory.java

public static void main(String[] args) {
    @SuppressWarnings("unused")
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("META-INF/SpringContext.xml");

    for (DataSourceMap m : DataSourceUtil.getDataSourceMap()) {

        DataSource ds = m.getDataSource();
        try {/*ww w.  j a va 2s .  c o  m*/
            Connection con = ds.getConnection();
            DatabaseMetaData dmd = con.getMetaData();
            String catalog = con.getCatalog();
            String schemaPattern = dmd.getSchemaTerm();
            System.out.println("Catalog:" + con.getCatalog() + " schemaPattern:" + schemaPattern);
            ResultSet rs = dmd.getTables(catalog, schemaPattern, "time_zone_transition", null);

            Statement s = null;
            ResultSet xrs = null;
            try {
                s = con.createStatement();
                xrs = s.executeQuery("select * from time_zone_transition");
                if (xrs.next()) {
                    p("xxxxxxxxxxxxxxxxxxxxxxxx:" + xrs.getString(1));
                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
            }

            while (rs.next()) {
                p("-----------------------");
                p("TABLE_CAT  :" + rs.getString("TABLE_CAT"));
                p("TABLE_SCHEM:" + rs.getString("TABLE_SCHEM"));
                p("TABLE_NAME :" + rs.getString("TABLE_NAME"));
                p("TABLE_TYPE :" + rs.getString("TABLE_TYPE"));
                p("REMARKS:   " + rs.getString("REMARKS"));

                p("11111111111111111:" + rs.getMetaData().getColumnClassName(1));
                // 
                ResultSet pkeyRs = dmd.getPrimaryKeys(catalog, schemaPattern, rs.getString("TABLE_NAME"));
                while (pkeyRs.next()) {
                    p("M-------------M");
                    p("------COLUMN_NAME:" + pkeyRs.getString("COLUMN_NAME"));
                    p("------KEY_SEQ:" + pkeyRs.getString("KEY_SEQ"));
                    p("------PK_NAME:" + pkeyRs.getString("PK_NAME"));
                }
                // 
                ResultSet rss = dmd.getColumns(catalog, schemaPattern, rs.getString("TABLE_NAME"), null);
                int cCount = rss.getMetaData().getColumnCount();
                for (int i = 1; i <= cCount; i++) {
                    p("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
                    p("       getColumnClassName:" + rss.getMetaData().getColumnClassName(i));
                    p("       getColumnLabel:" + rss.getMetaData().getColumnLabel(i));
                    p("       getColumnName:" + rss.getMetaData().getColumnName(i));
                    p("       getColumnTypeName:" + rss.getMetaData().getColumnTypeName(i));
                    p("       getColumnType:" + ColumnTypes.getType(rss.getMetaData().getColumnType(i)));
                }
            }
            rs = dmd.getTableTypes();

            while (rs.next()) {
                p("=========================");
                p("TABLE_TYPE: " + rs.getString("TABLE_TYPE"));
            }
            // ResultSetMetaData rsmd = rs.getMetaData();

            // int numberOfColumns = rsmd.getColumnCount();
            // for (int i = 1; i <= numberOfColumns; i++)
            // p(rsmd.getColumnName(i));
        } catch (SQLException e) {
            e.printStackTrace();
        }

        p(m.toString());
    }
}

From source file:de.griffel.confluence.plugins.plantuml.DatasourceHelper.java

public static List<String> getTableTypes(DatabaseMetaData dbmd) throws SQLException {
    final List<String> tableTypes = new LinkedList<String>();
    final ResultSet rs = dbmd.getTableTypes();
    while (rs.next()) {
        tableTypes.add(rs.getString(1));
    }/*from  w  w  w .  j  a va 2s. c  o  m*/
    rs.close();
    return tableTypes;
}

From source file:com.jaspersoft.studio.data.xvia.querydesigner.TrackViaMetadata.java

public static List<String> readTableTypes(DatabaseMetaData meta) throws SQLException {
    List<String> tableTypes = new ArrayList<String>();
    ResultSet rs = meta.getTableTypes();
    while (rs.next())
        tableTypes.add(rs.getString("TABLE_TYPE")); //$NON-NLS-1$
    rs.close();// ww  w  .ja  v a  2  s.c o m
    return tableTypes;
}

From source file:DatabaseInfo.java

public void doGet(HttpServletRequest inRequest, HttpServletResponse outResponse)
        throws ServletException, IOException {

    PrintWriter out = null;/*from ww  w . j a v a2  s  .c  om*/
    Connection connection = null;
    Statement statement;
    ResultSet rs;

    outResponse.setContentType("text/html");
    out = outResponse.getWriter();

    try {
        Context ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/AccountsDB");
        connection = ds.getConnection();

        DatabaseMetaData md = connection.getMetaData();
        statement = connection.createStatement();

        out.println("<HTML><HEAD><TITLE>Database Server Information</TITLE></HEAD>");
        out.println("<BODY>");
        out.println("<H1>General Source Information</H1>");
        out.println("getURL() - " + md.getURL() + "<BR>");
        out.println("getUserName() - " + md.getUserName() + "<BR>");
        out.println("getDatabaseProductVersion - " + md.getDatabaseProductVersion() + "<BR>");
        out.println("getDriverMajorVersion - " + md.getDriverMajorVersion() + "<BR>");
        out.println("getDriverMinorVersion - " + md.getDriverMinorVersion() + "<BR>");
        out.println("nullAreSortedHigh - " + md.nullsAreSortedHigh() + "<BR>");

        out.println("<H1>Feature Support</H1>");
        out.println("supportsAlterTableWithDropColumn - " + md.supportsAlterTableWithDropColumn() + "<BR>");
        out.println("supportsBatchUpdates - " + md.supportsBatchUpdates() + "<BR>");
        out.println("supportsTableCorrelationNames - " + md.supportsTableCorrelationNames() + "<BR>");
        out.println("supportsPositionedDelete - " + md.supportsPositionedDelete() + "<BR>");
        out.println("supportsFullOuterJoins - " + md.supportsFullOuterJoins() + "<BR>");
        out.println("supportsStoredProcedures - " + md.supportsStoredProcedures() + "<BR>");
        out.println("supportsMixedCaseQuotedIdentifiers - " + md.supportsMixedCaseQuotedIdentifiers() + "<BR>");
        out.println("supportsANSI92EntryLevelSQL - " + md.supportsANSI92EntryLevelSQL() + "<BR>");
        out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar() + "<BR>");

        out.println("<H1>Data Source Limits</H1>");
        out.println("getMaxRowSize - " + md.getMaxRowSize() + "<BR>");
        out.println("getMaxStatementLength - " + md.getMaxStatementLength() + "<BR>");
        out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect() + "<BR>");
        out.println("getMaxConnections - " + md.getMaxConnections() + "<BR>");
        out.println("getMaxCharLiteralLength - " + md.getMaxCharLiteralLength() + "<BR>");

        out.println("<H1>SQL Object Available</H1>");
        out.println("getTableTypes()<BR><UL>");
        rs = md.getTableTypes();
        while (rs.next()) {
            out.println("<LI>" + rs.getString(1));
        }
        out.println("</UL>");

        out.println("getTables()<BR><UL>");
        rs = md.getTables("accounts", "", "%", new String[0]);
        while (rs.next()) {
            out.println("<LI>" + rs.getString("TABLE_NAME"));
        }
        out.println("</UL>");

        out.println("<H1>Transaction Support</H1>");
        out.println("getDefaultTransactionIsolation() - " + md.getDefaultTransactionIsolation() + "<BR>");
        out.println(
                "dataDefinitionIgnoredInTransactions() - " + md.dataDefinitionIgnoredInTransactions() + "<BR>");

        out.println("<H1>General Source Information</H1>");
        out.println("getMaxTablesInSelect - " + md.getMaxTablesInSelect() + "<BR>");
        out.println("getMaxColumnsInTable - " + md.getMaxColumnsInTable() + "<BR>");
        out.println("getTimeDateFunctions - " + md.getTimeDateFunctions() + "<BR>");
        out.println("supportsCoreSQLGrammar - " + md.supportsCoreSQLGrammar() + "<BR>");

        out.println("getTypeInfo()<BR><UL>");
        rs = md.getTypeInfo();
        while (rs.next()) {
            out.println("<LI>" + rs.getString(1));
        }
        out.println("</UL>");

        out.println("</BODY></HTML>");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.apache.bigtop.itest.hive.TestJdbc.java

/**
 * Test simple DatabaseMetaData calls.  getColumns is tested elsewhere, as we need to call
 * that on a valid table.  Same with getFunctions.
 *
 * @throws SQLException/*from ww  w. ja  v a2  s .  c o m*/
 */
@Test
public void databaseMetaDataCalls() throws SQLException {
    DatabaseMetaData md = conn.getMetaData();

    boolean boolrc = md.allTablesAreSelectable();
    LOG.debug("All tables are selectable? " + boolrc);

    String strrc = md.getCatalogSeparator();
    LOG.debug("Catalog separator " + strrc);

    strrc = md.getCatalogTerm();
    LOG.debug("Catalog term " + strrc);

    ResultSet rs = md.getCatalogs();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found catalog " + strrc);
    }

    Connection c = md.getConnection();

    int intrc = md.getDatabaseMajorVersion();
    LOG.debug("DB major version is " + intrc);

    intrc = md.getDatabaseMinorVersion();
    LOG.debug("DB minor version is " + intrc);

    strrc = md.getDatabaseProductName();
    LOG.debug("DB product name is " + strrc);

    strrc = md.getDatabaseProductVersion();
    LOG.debug("DB product version is " + strrc);

    intrc = md.getDefaultTransactionIsolation();
    LOG.debug("Default transaction isolation is " + intrc);

    intrc = md.getDriverMajorVersion();
    LOG.debug("Driver major version is " + intrc);

    intrc = md.getDriverMinorVersion();
    LOG.debug("Driver minor version is " + intrc);

    strrc = md.getDriverName();
    LOG.debug("Driver name is " + strrc);

    strrc = md.getDriverVersion();
    LOG.debug("Driver version is " + strrc);

    strrc = md.getExtraNameCharacters();
    LOG.debug("Extra name characters is " + strrc);

    strrc = md.getIdentifierQuoteString();
    LOG.debug("Identifier quote string is " + strrc);

    // In Hive 1.2 this always returns an empty RS
    rs = md.getImportedKeys("a", "b", "d");

    // In Hive 1.2 this always returns an empty RS
    rs = md.getIndexInfo("a", "b", "d", true, true);

    intrc = md.getJDBCMajorVersion();
    LOG.debug("JDBC major version is " + intrc);

    intrc = md.getJDBCMinorVersion();
    LOG.debug("JDBC minor version is " + intrc);

    intrc = md.getMaxColumnNameLength();
    LOG.debug("Maximum column name length is " + intrc);

    strrc = md.getNumericFunctions();
    LOG.debug("Numeric functions are " + strrc);

    // In Hive 1.2 this always returns an empty RS
    rs = md.getPrimaryKeys("a", "b", "d");

    // In Hive 1.2 this always returns an empty RS
    rs = md.getProcedureColumns("a", "b", "d", "e");

    strrc = md.getProcedureTerm();
    LOG.debug("Procedures are called " + strrc);

    // In Hive 1.2 this always returns an empty RS
    rs = md.getProcedures("a", "b", "d");

    strrc = md.getSchemaTerm();
    LOG.debug("Schemas are called " + strrc);

    rs = md.getSchemas();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found schema " + strrc);
    }

    strrc = md.getSearchStringEscape();
    LOG.debug("Search string escape is " + strrc);

    strrc = md.getStringFunctions();
    LOG.debug("String functions are " + strrc);

    strrc = md.getSystemFunctions();
    LOG.debug("System functions are " + strrc);

    rs = md.getTableTypes();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found table type " + strrc);
    }

    strrc = md.getTimeDateFunctions();
    LOG.debug("Time/date functions are " + strrc);

    rs = md.getTypeInfo();
    while (rs.next()) {
        strrc = rs.getString(1);
        LOG.debug("Found type " + strrc);
    }

    // In Hive 1.2 this always returns an empty RS
    rs = md.getUDTs("a", "b", "d", null);

    boolrc = md.supportsAlterTableWithAddColumn();
    LOG.debug("Supports alter table with add column? " + boolrc);

    boolrc = md.supportsAlterTableWithDropColumn();
    LOG.debug("Supports alter table with drop column? " + boolrc);

    boolrc = md.supportsBatchUpdates();
    LOG.debug("Supports batch updates? " + boolrc);

    boolrc = md.supportsCatalogsInDataManipulation();
    LOG.debug("Supports catalogs in data manipulation? " + boolrc);

    boolrc = md.supportsCatalogsInIndexDefinitions();
    LOG.debug("Supports catalogs in index definition? " + boolrc);

    boolrc = md.supportsCatalogsInPrivilegeDefinitions();
    LOG.debug("Supports catalogs in privilege definition? " + boolrc);

    boolrc = md.supportsCatalogsInProcedureCalls();
    LOG.debug("Supports catalogs in procedure calls? " + boolrc);

    boolrc = md.supportsCatalogsInTableDefinitions();
    LOG.debug("Supports catalogs in table definition? " + boolrc);

    boolrc = md.supportsColumnAliasing();
    LOG.debug("Supports column aliasing? " + boolrc);

    boolrc = md.supportsFullOuterJoins();
    LOG.debug("Supports full outer joins? " + boolrc);

    boolrc = md.supportsGroupBy();
    LOG.debug("Supports group by? " + boolrc);

    boolrc = md.supportsLimitedOuterJoins();
    LOG.debug("Supports limited outer joins? " + boolrc);

    boolrc = md.supportsMultipleResultSets();
    LOG.debug("Supports limited outer joins? " + boolrc);

    boolrc = md.supportsNonNullableColumns();
    LOG.debug("Supports non-nullable columns? " + boolrc);

    boolrc = md.supportsOuterJoins();
    LOG.debug("Supports outer joins? " + boolrc);

    boolrc = md.supportsPositionedDelete();
    LOG.debug("Supports positioned delete? " + boolrc);

    boolrc = md.supportsPositionedUpdate();
    LOG.debug("Supports positioned update? " + boolrc);

    boolrc = md.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
    LOG.debug("Supports result set holdability? " + boolrc);

    boolrc = md.supportsResultSetType(ResultSet.HOLD_CURSORS_OVER_COMMIT);
    LOG.debug("Supports result set type? " + boolrc);

    boolrc = md.supportsSavepoints();
    LOG.debug("Supports savepoints? " + boolrc);

    boolrc = md.supportsSchemasInDataManipulation();
    LOG.debug("Supports schemas in data manipulation? " + boolrc);

    boolrc = md.supportsSchemasInIndexDefinitions();
    LOG.debug("Supports schemas in index definitions? " + boolrc);

    boolrc = md.supportsSchemasInPrivilegeDefinitions();
    LOG.debug("Supports schemas in privilege definitions? " + boolrc);

    boolrc = md.supportsSchemasInProcedureCalls();
    LOG.debug("Supports schemas in procedure calls? " + boolrc);

    boolrc = md.supportsSchemasInTableDefinitions();
    LOG.debug("Supports schemas in table definitions? " + boolrc);

    boolrc = md.supportsSelectForUpdate();
    LOG.debug("Supports select for update? " + boolrc);

    boolrc = md.supportsStoredProcedures();
    LOG.debug("Supports stored procedures? " + boolrc);

    boolrc = md.supportsTransactions();
    LOG.debug("Supports transactions? " + boolrc);

    boolrc = md.supportsUnion();
    LOG.debug("Supports union? " + boolrc);

    boolrc = md.supportsUnionAll();
    LOG.debug("Supports union all? " + boolrc);

}

From source file:org.apache.ddlutils.task.DumpMetadataTask.java

/**
 * Dumps all tables./*from w w  w .  ja  v  a  2s. c om*/
 * 
 * @param xmlWriter The xml writer to write to
 * @param metaData  The database metadata
 */
private void dumpTables(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData) {
    // First we need the list of supported table types
    final ArrayList tableTypeList = new ArrayList();

    performResultSetXmlOperation(xmlWriter, "tableTypes", new ResultSetXmlOperation() {
        public ResultSet getResultSet() throws SQLException {
            return metaData.getTableTypes();
        }

        public void handleRow(PrettyPrintingXmlWriter xmlWriter, ResultSet result) throws SQLException {
            String tableType = result.getString("TABLE_TYPE");

            tableTypeList.add(tableType);
            xmlWriter.writeElementStart(null, "tableType");
            xmlWriter.writeAttribute(null, "name", tableType);
            xmlWriter.writeElementEnd();
        }

        public void handleError(SQLException ex) {
            log("Could not read the table types from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
        }
    });

    final String[] tableTypesToRead;

    if ((_tableTypes == null) || (_tableTypes.length == 0)) {
        tableTypesToRead = (String[]) tableTypeList.toArray(new String[tableTypeList.size()]);
    } else {
        tableTypesToRead = _tableTypes;
    }

    performResultSetXmlOperation(xmlWriter, "tables", new ResultSetXmlOperation() {
        public ResultSet getResultSet() throws SQLException {
            return metaData.getTables(_catalogPattern, _schemaPattern, _tablePattern, tableTypesToRead);
        }

        public void handleRow(PrettyPrintingXmlWriter xmlWriter, ResultSet result) throws SQLException {
            Set columns = getColumnsInResultSet(result);
            String tableName = result.getString("TABLE_NAME");

            if ((tableName != null) && (tableName.length() > 0)) {
                String catalog = result.getString("TABLE_CAT");
                String schema = result.getString("TABLE_SCHEM");

                log("Reading table " + ((schema != null) && (schema.length() > 0) ? schema + "." : "")
                        + tableName, Project.MSG_INFO);

                xmlWriter.writeElementStart(null, "table");
                xmlWriter.writeAttribute(null, "name", tableName);
                if (catalog != null) {
                    xmlWriter.writeAttribute(null, "catalog", catalog);
                }
                if (schema != null) {
                    xmlWriter.writeAttribute(null, "schema", schema);
                }
                addStringAttribute(xmlWriter, "type", result, columns, "TABLE_TYPE");
                addStringAttribute(xmlWriter, "remarks", result, columns, "REMARKS");
                addStringAttribute(xmlWriter, "typeName", result, columns, "TYPE_NAME");
                addStringAttribute(xmlWriter, "typeCatalog", result, columns, "TYPE_CAT");
                addStringAttribute(xmlWriter, "typeSchema", result, columns, "TYPE_SCHEM");
                addStringAttribute(xmlWriter, "identifierColumn", result, columns, "SELF_REFERENCING_COL_NAME");
                addStringAttribute(xmlWriter, "identifierGeneration", result, columns, "REF_GENERATION");

                dumpColumns(xmlWriter, metaData, catalog, schema, tableName);
                dumpPKs(xmlWriter, metaData, catalog, schema, tableName);
                dumpVersionColumns(xmlWriter, metaData, catalog, schema, tableName);
                dumpFKs(xmlWriter, metaData, catalog, schema, tableName);
                dumpIndexes(xmlWriter, metaData, catalog, schema, tableName);

                xmlWriter.writeElementEnd();
            }
        }

        public void handleError(SQLException ex) {
            log("Could not read the tables from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
        }
    });
}

From source file:org.apache.hive.jdbc.TestJdbcDriver2.java

@Test
public void testParentReferences() throws Exception {
    /* Test parent references from Statement */
    Statement s = this.con.createStatement();
    ResultSet rs = s.executeQuery("SELECT * FROM " + dataTypeTableName);

    assertTrue(s.getConnection() == this.con);
    assertTrue(rs.getStatement() == s);/*w  w w  .  j  a  va 2  s  .c om*/

    rs.close();
    s.close();

    /* Test parent references from PreparedStatement */
    PreparedStatement ps = this.con.prepareStatement("SELECT * FROM " + dataTypeTableName);
    rs = ps.executeQuery();

    assertTrue(ps.getConnection() == this.con);
    assertTrue(rs.getStatement() == ps);

    rs.close();
    ps.close();

    /* Test DatabaseMetaData queries which do not have a parent Statement */
    DatabaseMetaData md = this.con.getMetaData();

    assertTrue(md.getConnection() == this.con);

    rs = md.getCatalogs();
    assertNull(rs.getStatement());
    rs.close();

    rs = md.getColumns(null, null, null, null);
    assertNull(rs.getStatement());
    rs.close();

    rs = md.getFunctions(null, null, null);
    assertNull(rs.getStatement());
    rs.close();

    rs = md.getImportedKeys(null, null, null);
    assertNull(rs.getStatement());
    rs.close();

    rs = md.getPrimaryKeys(null, null, null);
    assertNull(rs.getStatement());
    rs.close();

    rs = md.getProcedureColumns(null, null, null, null);
    assertNull(rs.getStatement());
    rs.close();

    rs = md.getProcedures(null, null, null);
    assertNull(rs.getStatement());
    rs.close();

    rs = md.getSchemas();
    assertNull(rs.getStatement());
    rs.close();

    rs = md.getTableTypes();
    assertNull(rs.getStatement());
    rs.close();

    rs = md.getTables(null, null, null, null);
    assertNull(rs.getStatement());
    rs.close();

    rs = md.getTypeInfo();
    assertNull(rs.getStatement());
    rs.close();
}