Example usage for java.sql SQLException getStackTrace

List of usage examples for java.sql SQLException getStackTrace

Introduction

In this page you can find the example usage for java.sql SQLException getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

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

/**
 * Dumps all tables./*from w ww .  java 2 s.c o  m*/
 * 
 * @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.ddlutils.task.DumpMetadataTask.java

/**
 * Dumps the columns of the indicated table.
 * //  w  ww.  j a  v  a  2 s  . c o  m
 * @param xmlWriter   The xml writer to write to
 * @param metaData    The database metadata
 * @param catalogName The catalog name
 * @param schemaName  The schema name
 * @param tableName   The table name
 */
private void dumpColumns(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData,
        final String catalogName, final String schemaName, final String tableName) throws SQLException {
    performResultSetXmlOperation(xmlWriter, null, new ResultSetXmlOperation() {
        public ResultSet getResultSet() throws SQLException {
            return metaData.getColumns(catalogName, schemaName, tableName, _columnPattern);
        }

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

            if ((columnName != null) && (columnName.length() > 0)) {
                xmlWriter.writeElementStart(null, "column");
                xmlWriter.writeAttribute(null, "name", columnName);

                addIntAttribute(xmlWriter, "typeCode", result, columns, "DATA_TYPE");
                addStringAttribute(xmlWriter, "type", result, columns, "TYPE_NAME");
                addIntAttribute(xmlWriter, "size", result, columns, "COLUMN_SIZE");
                addIntAttribute(xmlWriter, "digits", result, columns, "DECIMAL_DIGITS");
                addIntAttribute(xmlWriter, "precision", result, columns, "NUM_PREC_RADIX");
                if (columns.contains("NULLABLE")) {
                    try {
                        switch (result.getInt("NULLABLE")) {
                        case DatabaseMetaData.columnNoNulls:
                            xmlWriter.writeAttribute(null, "nullable", "false");
                            break;
                        case DatabaseMetaData.columnNullable:
                            xmlWriter.writeAttribute(null, "nullable", "true");
                            break;
                        default:
                            xmlWriter.writeAttribute(null, "nullable", "unknown");
                            break;
                        }
                    } catch (SQLException ex) {
                        log("Could not read the NULLABLE value for colum '" + columnName + "' of table '"
                                + tableName + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
                    }
                }
                addStringAttribute(xmlWriter, "remarks", result, columns, "REMARKS");
                addStringAttribute(xmlWriter, "defaultValue", result, columns, "COLUMN_DEF");
                addIntAttribute(xmlWriter, "maxByteLength", result, columns, "CHAR_OCTET_LENGTH");
                addIntAttribute(xmlWriter, "index", result, columns, "ORDINAL_POSITION");
                if (columns.contains("IS_NULLABLE")) {
                    try {
                        String value = result.getString("IS_NULLABLE");

                        if ("no".equalsIgnoreCase(value)) {
                            xmlWriter.writeAttribute(null, "isNullable", "false");
                        } else if ("yes".equalsIgnoreCase(value)) {
                            xmlWriter.writeAttribute(null, "isNullable", "true");
                        } else {
                            xmlWriter.writeAttribute(null, "isNullable", "unknown");
                        }
                    } catch (SQLException ex) {
                        log("Could not read the IS_NULLABLE value for colum '" + columnName + "' of table '"
                                + tableName + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
                    }
                }
                addStringAttribute(xmlWriter, "refCatalog", result, columns, "SCOPE_CATLOG");
                addStringAttribute(xmlWriter, "refSchema", result, columns, "SCOPE_SCHEMA");
                addStringAttribute(xmlWriter, "refTable", result, columns, "SCOPE_TABLE");
                addShortAttribute(xmlWriter, "sourceTypeCode", result, columns, "SOURCE_DATA_TYPE");

                xmlWriter.writeElementEnd();
            }
        }

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

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

/**
 * Dumps the primary key columns of the indicated table.
 * //ww  w  .j a  v  a  2 s . co m
 * @param xmlWriter   The xml writer to write to
 * @param metaData    The database metadata
 * @param catalogName The catalog name
 * @param schemaName  The schema name
 * @param tableName   The table name
 */
private void dumpPKs(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData,
        final String catalogName, final String schemaName, final String tableName) throws SQLException {
    performResultSetXmlOperation(xmlWriter, null, new ResultSetXmlOperation() {
        public ResultSet getResultSet() throws SQLException {
            return metaData.getPrimaryKeys(catalogName, schemaName, tableName);
        }

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

            if ((columnName != null) && (columnName.length() > 0)) {
                xmlWriter.writeElementStart(null, "primaryKey");
                xmlWriter.writeAttribute(null, "column", columnName);

                addStringAttribute(xmlWriter, "name", result, columns, "PK_NAME");
                addShortAttribute(xmlWriter, "sequenceNumberInPK", result, columns, "KEY_SEQ");

                xmlWriter.writeElementEnd();
            }
        }

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

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

/**
 * Dumps the versioned (auto-updating) columns of the indicated table.
 * //w  w w .ja va2s.co m
 * @param xmlWriter   The xml writer to write to
 * @param metaData    The database metadata
 * @param catalogName The catalog name
 * @param schemaName  The schema name
 * @param tableName   The table name
 */
private void dumpVersionColumns(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData,
        final String catalogName, final String schemaName, final String tableName) throws SQLException {
    performResultSetXmlOperation(xmlWriter, null, new ResultSetXmlOperation() {
        public ResultSet getResultSet() throws SQLException {
            return metaData.getVersionColumns(catalogName, schemaName, tableName);
        }

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

            if ((columnName != null) && (columnName.length() > 0)) {
                xmlWriter.writeElementStart(null, "versionedColumn");
                xmlWriter.writeAttribute(null, "column", columnName);

                addIntAttribute(xmlWriter, "typeCode", result, columns, "DATA_TYPE");
                addStringAttribute(xmlWriter, "type", result, columns, "TYPE_NAME");
                addIntAttribute(xmlWriter, "size", result, columns, "BUFFER_LENGTH");
                addIntAttribute(xmlWriter, "precision", result, columns, "COLUMN_SIZE");
                addShortAttribute(xmlWriter, "scale", result, columns, "DECIMAL_DIGITS");
                if (columns.contains("PSEUDO_COLUMN")) {
                    try {
                        switch (result.getShort("PSEUDO_COLUMN")) {
                        case DatabaseMetaData.versionColumnPseudo:
                            xmlWriter.writeAttribute(null, "columnType", "pseudo column");
                            break;
                        case DatabaseMetaData.versionColumnNotPseudo:
                            xmlWriter.writeAttribute(null, "columnType", "real column");
                            break;
                        default:
                            xmlWriter.writeAttribute(null, "columnType", "unknown");
                            break;
                        }
                    } catch (SQLException ex) {
                        log("Could not read the PSEUDO_COLUMN value for versioned colum '" + columnName
                                + "' of table '" + tableName + "' from the result set: " + ex.getStackTrace(),
                                Project.MSG_ERR);
                    }
                }
                xmlWriter.writeElementEnd();
            }
        }

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

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

/**
 * Dumps the foreign key columns of the indicated table to other tables.
 * //  w  w w  . j  a va2s . c  om
 * @param xmlWriter   The xml writer to write to
 * @param metaData    The database metadata
 * @param catalogName The catalog name
 * @param schemaName  The schema name
 * @param tableName   The table name
 */
private void dumpFKs(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData,
        final String catalogName, final String schemaName, final String tableName) throws SQLException {
    performResultSetXmlOperation(xmlWriter, null, new ResultSetXmlOperation() {
        public ResultSet getResultSet() throws SQLException {
            return metaData.getImportedKeys(catalogName, schemaName, tableName);
        }

        public void handleRow(PrettyPrintingXmlWriter xmlWriter, ResultSet result) throws SQLException {
            Set columns = getColumnsInResultSet(result);

            xmlWriter.writeElementStart(null, "foreignKey");

            addStringAttribute(xmlWriter, "name", result, columns, "FK_NAME");
            addStringAttribute(xmlWriter, "primaryKeyName", result, columns, "PK_NAME");
            addStringAttribute(xmlWriter, "column", result, columns, "PKCOLUMN_NAME");
            addStringAttribute(xmlWriter, "foreignCatalog", result, columns, "FKTABLE_CAT");
            addStringAttribute(xmlWriter, "foreignSchema", result, columns, "FKTABLE_SCHEM");
            addStringAttribute(xmlWriter, "foreignTable", result, columns, "FKTABLE_NAME");
            addStringAttribute(xmlWriter, "foreignColumn", result, columns, "FKCOLUMN_NAME");
            addShortAttribute(xmlWriter, "sequenceNumberInFK", result, columns, "KEY_SEQ");
            if (columns.contains("UPDATE_RULE")) {
                try {
                    switch (result.getShort("UPDATE_RULE")) {
                    case DatabaseMetaData.importedKeyNoAction:
                        xmlWriter.writeAttribute(null, "updateRule", "no action");
                        break;
                    case DatabaseMetaData.importedKeyCascade:
                        xmlWriter.writeAttribute(null, "updateRule", "cascade PK change");
                        break;
                    case DatabaseMetaData.importedKeySetNull:
                        xmlWriter.writeAttribute(null, "updateRule", "set FK to NULL");
                        break;
                    case DatabaseMetaData.importedKeySetDefault:
                        xmlWriter.writeAttribute(null, "updateRule", "set FK to default");
                        break;
                    default:
                        xmlWriter.writeAttribute(null, "updateRule", "unknown");
                        break;
                    }
                } catch (SQLException ex) {
                    log("Could not read the UPDATE_RULE value for a foreign key of table '" + tableName
                            + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
                }
            }
            if (columns.contains("DELETE_RULE")) {
                try {
                    switch (result.getShort("DELETE_RULE")) {
                    case DatabaseMetaData.importedKeyNoAction:
                    case DatabaseMetaData.importedKeyRestrict:
                        xmlWriter.writeAttribute(null, "deleteRule", "no action");
                        break;
                    case DatabaseMetaData.importedKeyCascade:
                        xmlWriter.writeAttribute(null, "deleteRule", "cascade PK change");
                        break;
                    case DatabaseMetaData.importedKeySetNull:
                        xmlWriter.writeAttribute(null, "deleteRule", "set FK to NULL");
                        break;
                    case DatabaseMetaData.importedKeySetDefault:
                        xmlWriter.writeAttribute(null, "deleteRule", "set FK to default");
                        break;
                    default:
                        xmlWriter.writeAttribute(null, "deleteRule", "unknown");
                        break;
                    }
                } catch (SQLException ex) {
                    log("Could not read the DELETE_RULE value for a foreign key of table '" + tableName
                            + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
                }
            }
            if (columns.contains("DEFERRABILITY")) {
                try {
                    switch (result.getShort("DEFERRABILITY")) {
                    case DatabaseMetaData.importedKeyInitiallyDeferred:
                        xmlWriter.writeAttribute(null, "deferrability", "initially deferred");
                        break;
                    case DatabaseMetaData.importedKeyInitiallyImmediate:
                        xmlWriter.writeAttribute(null, "deferrability", "immediately deferred");
                        break;
                    case DatabaseMetaData.importedKeyNotDeferrable:
                        xmlWriter.writeAttribute(null, "deferrability", "not deferred");
                        break;
                    default:
                        xmlWriter.writeAttribute(null, "deferrability", "unknown");
                        break;
                    }
                } catch (SQLException ex) {
                    log("Could not read the DEFERRABILITY value for a foreign key of table '" + tableName
                            + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
                }
            }
            xmlWriter.writeElementEnd();
        }

        public void handleError(SQLException ex) {
            log("Could not determine the foreign keys for table '" + tableName + "': " + ex.getStackTrace(),
                    Project.MSG_ERR);
        }
    });
}

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

/**
 * Dumps the indexes of the indicated table.
 * /*w  w  w. ja va2s. com*/
 * @param xmlWriter   The xml writer to write to
 * @param metaData    The database metadata
 * @param catalogName The catalog name
 * @param schemaName  The schema name
 * @param tableName   The table name
 */
private void dumpIndexes(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData,
        final String catalogName, final String schemaName, final String tableName) throws SQLException {
    performResultSetXmlOperation(xmlWriter, null, new ResultSetXmlOperation() {
        public ResultSet getResultSet() throws SQLException {
            return metaData.getIndexInfo(catalogName, schemaName, tableName, false, false);
        }

        public void handleRow(PrettyPrintingXmlWriter xmlWriter, ResultSet result) throws SQLException {
            Set columns = getColumnsInResultSet(result);

            xmlWriter.writeElementStart(null, "index");

            addStringAttribute(xmlWriter, "name", result, columns, "INDEX_NAME");
            addBooleanAttribute(xmlWriter, "nonUnique", result, columns, "NON_UNIQUE");
            addStringAttribute(xmlWriter, "indexCatalog", result, columns, "INDEX_QUALIFIER");
            if (columns.contains("TYPE")) {
                try {
                    switch (result.getShort("TYPE")) {
                    case DatabaseMetaData.tableIndexStatistic:
                        xmlWriter.writeAttribute(null, "type", "table statistics");
                        break;
                    case DatabaseMetaData.tableIndexClustered:
                        xmlWriter.writeAttribute(null, "type", "clustered");
                        break;
                    case DatabaseMetaData.tableIndexHashed:
                        xmlWriter.writeAttribute(null, "type", "hashed");
                        break;
                    case DatabaseMetaData.tableIndexOther:
                        xmlWriter.writeAttribute(null, "type", "other");
                        break;
                    default:
                        xmlWriter.writeAttribute(null, "type", "unknown");
                        break;
                    }
                } catch (SQLException ex) {
                    log("Could not read the TYPE value for an index of table '" + tableName
                            + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
                }
            }
            addStringAttribute(xmlWriter, "column", result, columns, "COLUMN_NAME");
            addShortAttribute(xmlWriter, "sequenceNumberInIndex", result, columns, "ORDINAL_POSITION");
            if (columns.contains("ASC_OR_DESC")) {
                try {
                    String value = result.getString("ASC_OR_DESC");

                    if ("A".equalsIgnoreCase(value)) {
                        xmlWriter.writeAttribute(null, "sortOrder", "ascending");
                    } else if ("D".equalsIgnoreCase(value)) {
                        xmlWriter.writeAttribute(null, "sortOrder", "descending");
                    } else {
                        xmlWriter.writeAttribute(null, "sortOrder", "unknown");
                    }
                } catch (SQLException ex) {
                    log("Could not read the ASC_OR_DESC value for an index of table '" + tableName
                            + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
                }
            }
            addIntAttribute(xmlWriter, "cardinality", result, columns, "CARDINALITY");
            addIntAttribute(xmlWriter, "pages", result, columns, "PAGES");
            addStringAttribute(xmlWriter, "filter", result, columns, "FILTER_CONDITION");
        }

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

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

/**
 * Dumps all procedures.//from   w w  w .  j  a v  a2s  . c  o m
 * 
 * @param xmlWriter The xml writer to write to
 * @param metaData  The database metadata
 */
private void dumpProcedures(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData)
        throws SQLException {
    performResultSetXmlOperation(xmlWriter, "procedures", new ResultSetXmlOperation() {
        public ResultSet getResultSet() throws SQLException {
            return metaData.getProcedures(_catalogPattern, _schemaPattern, _procedurePattern);
        }

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

            if ((procedureName != null) && (procedureName.length() > 0)) {
                String catalog = result.getString("PROCEDURE_CAT");
                String schema = result.getString("PROCEDURE_SCHEM");

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

                xmlWriter.writeElementStart(null, "procedure");
                xmlWriter.writeAttribute(null, "name", procedureName);
                if (catalog != null) {
                    xmlWriter.writeAttribute(null, "catalog", catalog);
                }
                if (schema != null) {
                    xmlWriter.writeAttribute(null, "schema", schema);
                }
                addStringAttribute(xmlWriter, "remarks", result, columns, "REMARKS");
                if (columns.contains("PROCEDURE_TYPE")) {
                    try {
                        switch (result.getShort("PROCEDURE_TYPE")) {
                        case DatabaseMetaData.procedureReturnsResult:
                            xmlWriter.writeAttribute(null, "type", "returns result");
                            break;
                        case DatabaseMetaData.procedureNoResult:
                            xmlWriter.writeAttribute(null, "type", "doesn't return result");
                            break;
                        case DatabaseMetaData.procedureResultUnknown:
                            xmlWriter.writeAttribute(null, "type", "may return result");
                            break;
                        default:
                            xmlWriter.writeAttribute(null, "type", "unknown");
                            break;
                        }
                    } catch (SQLException ex) {
                        log("Could not read the PROCEDURE_TYPE value for the procedure '" + procedureName
                                + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR);
                    }
                }

                dumpProcedure(xmlWriter, metaData, "%", "%", procedureName);
                xmlWriter.writeElementEnd();
            }
        }

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

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

/**
 * Dumps the contents of the indicated procedure.
 * //from w ww  . ja v a2  s  . c o  m
 * @param xmlWriter     The xml writer to write to
 * @param metaData      The database metadata
 * @param catalogName   The catalog name
 * @param schemaName    The schema name
 * @param procedureName The procedure name
 */
private void dumpProcedure(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData,
        final String catalogName, final String schemaName, final String procedureName) throws SQLException {
    performResultSetXmlOperation(xmlWriter, null, new ResultSetXmlOperation() {
        public ResultSet getResultSet() throws SQLException {
            return metaData.getProcedureColumns(catalogName, schemaName, procedureName, _columnPattern);
        }

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

            if ((columnName != null) && (columnName.length() > 0)) {
                xmlWriter.writeElementStart(null, "column");
                xmlWriter.writeAttribute(null, "name", columnName);
                if (columns.contains("COLUMN_TYPE")) {
                    try {
                        switch (result.getShort("COLUMN_TYPE")) {
                        case DatabaseMetaData.procedureColumnIn:
                            xmlWriter.writeAttribute(null, "type", "in parameter");
                            break;
                        case DatabaseMetaData.procedureColumnInOut:
                            xmlWriter.writeAttribute(null, "type", "in/out parameter");
                            break;
                        case DatabaseMetaData.procedureColumnOut:
                            xmlWriter.writeAttribute(null, "type", "out parameter");
                            break;
                        case DatabaseMetaData.procedureColumnReturn:
                            xmlWriter.writeAttribute(null, "type", "return value");
                            break;
                        case DatabaseMetaData.procedureColumnResult:
                            xmlWriter.writeAttribute(null, "type", "result column in ResultSet");
                            break;
                        default:
                            xmlWriter.writeAttribute(null, "type", "unknown");
                            break;
                        }
                    } catch (SQLException ex) {
                        log("Could not read the COLUMN_TYPE value for the column '" + columnName
                                + "' of procedure '" + procedureName + "' from the result set: "
                                + ex.getStackTrace(), Project.MSG_ERR);
                    }
                }

                addIntAttribute(xmlWriter, "typeCode", result, columns, "DATA_TYPE");
                addStringAttribute(xmlWriter, "type", result, columns, "TYPE_NAME");
                addIntAttribute(xmlWriter, "length", result, columns, "LENGTH");
                addIntAttribute(xmlWriter, "precision", result, columns, "PRECISION");
                addShortAttribute(xmlWriter, "short", result, columns, "SCALE");
                addShortAttribute(xmlWriter, "radix", result, columns, "RADIX");
                if (columns.contains("NULLABLE")) {
                    try {
                        switch (result.getInt("NULLABLE")) {
                        case DatabaseMetaData.procedureNoNulls:
                            xmlWriter.writeAttribute(null, "nullable", "false");
                            break;
                        case DatabaseMetaData.procedureNullable:
                            xmlWriter.writeAttribute(null, "nullable", "true");
                            break;
                        default:
                            xmlWriter.writeAttribute(null, "nullable", "unknown");
                            break;
                        }
                    } catch (SQLException ex) {
                        log("Could not read the NULLABLE value for the column '" + columnName
                                + "' of procedure '" + procedureName + "' from the result set: "
                                + ex.getStackTrace(), Project.MSG_ERR);
                    }
                }
                addStringAttribute(xmlWriter, "remarks", result, columns, "REMARKS");
            }
        }

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

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

/**
 * If the result set contains the indicated column, extracts its value and sets an attribute at the given element.
 * /*from  w w w  .j  a  v a 2 s .c o m*/
 * @param xmlWriter  The xml writer to write to
 * @param attrName   The name of the attribute to write
 * @param result     The result set
 * @param columns    The columns in the result set
 * @param columnName The name of the column in the result set
 */
private void addStringAttribute(PrettyPrintingXmlWriter xmlWriter, String attrName, ResultSet result,
        Set columns, String columnName) throws SQLException {
    if (columns.contains(columnName)) {
        try {
            xmlWriter.writeAttribute(null, attrName, result.getString(columnName));
        } catch (SQLException ex) {
            log("Could not read the value from result set column " + columnName + ":" + ex.getStackTrace(),
                    Project.MSG_ERR);
        }
    }
}

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

/**
 * If the result set contains the indicated column, extracts its int value and sets an attribute at the given element.
 * /*from  w  w  w.  ja v a 2  s  . com*/
 * @param xmlWriter  The xml writer to write to
 * @param attrName   The name of the attribute to write
 * @param result     The result set
 * @param columns    The columns in the result set
 * @param columnName The name of the column in the result set
 */
private void addIntAttribute(PrettyPrintingXmlWriter xmlWriter, String attrName, ResultSet result, Set columns,
        String columnName) throws SQLException {
    if (columns.contains(columnName)) {
        try {
            xmlWriter.writeAttribute(null, attrName, String.valueOf(result.getInt(columnName)));
        } catch (SQLException ex) {
            // A few databases do not comply with the jdbc spec and return a string (or null),
            // so lets try this just in case
            String value = result.getString(columnName);

            if (value != null) {
                try {
                    xmlWriter.writeAttribute(null, attrName, new Integer(value).toString());
                } catch (NumberFormatException parseEx) {
                    log("Could not parse the value from result set column " + columnName + ":"
                            + ex.getStackTrace(), Project.MSG_ERR);
                }
            }
        }
    }
}