Example usage for java.sql Types BLOB

List of usage examples for java.sql Types BLOB

Introduction

In this page you can find the example usage for java.sql Types BLOB.

Prototype

int BLOB

To view the source code for java.sql Types BLOB.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BLOB.

Usage

From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatUtilities.java

/**
* Resolve a database-specific type to HCat data type. Largely follows Sqoop's
* hive translation./*from  w w  w  .jav  a 2 s  .c om*/
* @param sqlType
*          sql type
* @return hcat type
*/
public static String toHCatType(int sqlType) {
    switch (sqlType) {

    // Ideally TINYINT and SMALLINT should be mapped to their
    // HCat equivalents tinyint and smallint respectively
    // But the Sqoop Java type conversion has them mapped to Integer
    // Even though the referenced Java doc clearly recommends otherwise.
    // Changing this now can cause many of the sequence file usages to
    // break as value class implementations will change. So, we
    // just use the same behavior here.
    case Types.SMALLINT:
    case Types.TINYINT:
    case Types.INTEGER:
        return "int";

    case Types.VARCHAR:
        return "varchar";
    case Types.CHAR:
        return "char";
    case Types.LONGVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
    case Types.LONGNVARCHAR:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
    case Types.CLOB:
        return "string";

    case Types.FLOAT:
    case Types.REAL:
        return "float";

    case Types.NUMERIC:
    case Types.DECIMAL:
        return "decimal";

    case Types.DOUBLE:
        return "double";

    case Types.BIT:
    case Types.BOOLEAN:
        return "boolean";

    case Types.BIGINT:
        return "bigint";

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB:
    case Types.LONGVARBINARY:
        return "binary";

    default:
        throw new IllegalArgumentException("Cannot convert SQL type to HCatalog type " + sqlType);
    }
}

From source file:org.jumpmind.symmetric.db.AbstractTriggerTemplate.java

protected String buildKeyVariablesDeclare(Column[] columns, String prefix) {
    String text = "";
    for (int i = 0; i < columns.length; i++) {
        text += "declare @" + prefix + "pk" + i + " ";
        switch (columns[i].getMappedTypeCode()) {
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
            text += "bigint\n";
            break;
        case Types.NUMERIC:
        case Types.DECIMAL:
            text += "decimal\n";
            break;
        case Types.FLOAT:
        case Types.REAL:
        case Types.DOUBLE:
            text += "float\n";
            break;
        case Types.CHAR:
        case Types.VARCHAR:
        case ColumnTypes.NVARCHAR:
        case ColumnTypes.LONGNVARCHAR:
        case Types.LONGVARCHAR:
            text += "varchar(1000)\n";
            break;
        case Types.DATE:
            text += "date\n";
            break;
        case Types.TIME:
            text += "time\n";
            break;
        case Types.TIMESTAMP:
            text += "datetime\n";
            break;
        case Types.BOOLEAN:
        case Types.BIT:
            text += "bit\n";
            break;
        case Types.CLOB:
            text += "varchar(max)\n";
            break;
        case Types.BLOB:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case -10: // SQL-Server ntext binary type
            text += "varbinary(max)\n";
            break;
        case Types.OTHER:
            text += "varbinary(max)\n";
            break;
        default://from  www  . ja v  a 2 s . c o  m
            if (columns[i].getJdbcTypeName() != null
                    && columns[i].getJdbcTypeName().equalsIgnoreCase("interval")) {
                text += "interval";
                break;
            }
            throw new NotImplementedException(columns[i] + " is of type " + columns[i].getMappedType());
        }
    }

    return text;
}

From source file:com.mirth.connect.donkey.test.util.TestUtils.java

private static String typeToString(int sqlType) {
    switch (sqlType) {
    case Types.ARRAY:
        return "ARRAY";
    case Types.BIGINT:
        return "BIGINT";
    case Types.BINARY:
        return "BINARY";
    case Types.BIT:
        return "BIT";
    case Types.BLOB:
        return "BLOB";
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.CHAR:
        return "CHAR";
    case Types.CLOB:
        return "CLOB";
    case Types.DATALINK:
        return "DATALINK";
    case Types.DATE:
        return "DATE";
    case Types.DECIMAL:
        return "DECIMAL";
    case Types.DISTINCT:
        return "DISTINCT";
    case Types.DOUBLE:
        return "DOUBLE";
    case Types.FLOAT:
        return "FLOAT";
    case Types.INTEGER:
        return "INTEGER";
    case Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case Types.LONGNVARCHAR:
        return "LONGNVARCHAR";
    case Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case Types.LONGVARCHAR:
        return "LONGVARCHAR";
    case Types.NCHAR:
        return "NCHAR";
    case Types.NCLOB:
        return "NCLOB";
    case Types.NULL:
        return "NULL";
    case Types.NUMERIC:
        return "NUMERIC";
    case Types.NVARCHAR:
        return "NVARCHAR";
    case Types.OTHER:
        return "OTHER";
    case Types.REAL:
        return "REAL";
    case Types.REF:
        return "REF";
    case Types.ROWID:
        return "ROWID";
    case Types.SMALLINT:
        return "SMALLINT";
    case Types.SQLXML:
        return "SQLXML";
    case Types.STRUCT:
        return "STRUCT";
    case Types.TIME:
        return "TIME";
    case Types.TIMESTAMP:
        return "TIMESTAMP";
    case Types.TINYINT:
        return "TINYINT";
    case Types.VARBINARY:
        return "VARBINARY";
    case Types.VARCHAR:
        return "VARCHAR";
    default://  w  w w .  j a  v  a 2  s  .c  o  m
        return "UNKNOWN";
    }
}

From source file:org.apache.openjpa.persistence.jdbc.AnnotationPersistenceMappingParser.java

@Override
protected void parseLobMapping(FieldMetaData fmd) {
    Column col = new Column();
    int typeCode = fmd.isElementCollection() ? fmd.getElement().getDeclaredTypeCode()
            : fmd.getDeclaredTypeCode();
    Class<?> type = fmd.isElementCollection() ? fmd.getElement().getDeclaredType() : fmd.getDeclaredType();

    if (typeCode == JavaTypes.STRING || type == char[].class || type == Character[].class)
        col.setType(Types.CLOB);//from  www  .  j a v  a2s .  co m
    else
        col.setType(Types.BLOB);
    if (fmd.isElementCollection())
        ((FieldMapping) fmd).getElementMapping().getValueInfo().setColumns(Arrays.asList(new Column[] { col }));
    else
        ((FieldMapping) fmd).getValueInfo().setColumns(Arrays.asList(new Column[] { col }));

}

From source file:org.wso2.carbon.dataservices.core.description.query.SQLQuery.java

private DataEntry getDataEntryFromRS(ResultSet rs) throws SQLException {
    DataEntry dataEntry = new DataEntry();
    ResultSetMetaData metaData = rs.getMetaData();
    int columnCount = metaData.getColumnCount();
    int columnType;
    String value;//  ww w . j av a  2s. c o  m
    ParamValue paramValue;
    Time sqlTime;
    Date sqlDate;
    Timestamp sqlTimestamp;
    Blob sqlBlob;
    BigDecimal bigDecimal;
    InputStream binInStream;
    boolean useColumnNumbers = this.isUsingColumnNumbers();
    for (int i = 1; i <= columnCount; i++) {
        /* retrieve values according to the column type */
        columnType = metaData.getColumnType(i);
        switch (columnType) {
        /* handle string types */
        case Types.VARCHAR:
            /* fall through */
        case Types.LONGVARCHAR:
            /* fall through */
        case Types.CHAR:
            /* fall through */
        case Types.CLOB:
            /* fall through */
        case Types.NCHAR:
            /* fall through */
        case Types.NCLOB:
            /* fall through */
        case Types.NVARCHAR:
            /* fall through */
        case Types.LONGNVARCHAR:
            value = rs.getString(i);
            paramValue = new ParamValue(value);
            break;
        /* handle numbers */
        case Types.INTEGER:
            /* fall through */
        case Types.TINYINT:
            /* fall through */
        case Types.SMALLINT:
            value = ConverterUtil.convertToString(rs.getInt(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.DOUBLE:
            value = ConverterUtil.convertToString(rs.getDouble(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.FLOAT:
            value = ConverterUtil.convertToString(rs.getFloat(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.BOOLEAN:
            /* fall through */
        case Types.BIT:
            value = ConverterUtil.convertToString(rs.getBoolean(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.DECIMAL:
            bigDecimal = rs.getBigDecimal(i);
            if (bigDecimal != null) {
                value = ConverterUtil.convertToString(bigDecimal);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        /* handle data/time values */
        case Types.TIME:
            /* handle time data type */
            sqlTime = rs.getTime(i);
            if (sqlTime != null) {
                value = this.convertToTimeString(sqlTime);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.DATE:
            /* handle date data type */
            sqlDate = rs.getDate(i);
            if (sqlDate != null) {
                value = ConverterUtil.convertToString(sqlDate);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.TIMESTAMP:
            sqlTimestamp = rs.getTimestamp(i, calendar);
            if (sqlTimestamp != null) {
                value = this.convertToTimestampString(sqlTimestamp);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        /* handle binary types */
        case Types.BLOB:
            sqlBlob = rs.getBlob(i);
            if (sqlBlob != null) {
                value = this.getBase64StringFromInputStream(sqlBlob.getBinaryStream());
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.BINARY:
            /* fall through */
        case Types.LONGVARBINARY:
            /* fall through */
        case Types.VARBINARY:
            binInStream = rs.getBinaryStream(i);
            if (binInStream != null) {
                value = this.getBase64StringFromInputStream(binInStream);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        /* handling User Defined Types */
        case Types.STRUCT:
            Struct udt = (Struct) rs.getObject(i);
            paramValue = new ParamValue(udt);
            break;
        case Types.ARRAY:
            paramValue = new ParamValue(ParamValue.PARAM_VALUE_ARRAY);
            Array dataArray = (Array) rs.getObject(i);
            if (dataArray == null) {
                break;
            }
            paramValue = this.processSQLArray(dataArray, paramValue);
            break;
        case Types.NUMERIC:
            bigDecimal = rs.getBigDecimal(i);
            if (bigDecimal != null) {
                value = ConverterUtil.convertToString(bigDecimal);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.BIGINT:
            value = ConverterUtil.convertToString(rs.getLong(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;

        /* handle all other types as strings */
        default:
            value = rs.getString(i);
            paramValue = new ParamValue(value);
            break;
        }
        dataEntry.addValue(useColumnNumbers ? Integer.toString(i) : metaData.getColumnLabel(i), paramValue);
    }
    return dataEntry;
}

From source file:com.enonic.vertical.engine.handlers.MenuHandler.java

private int createMenuItem(User user, CopyContext copyContext, Element menuItemElement, SiteKey siteKey,
        int order, MenuItemKey parentKey, boolean useOldKey)
        throws VerticalCreateException, VerticalSecurityException {

    // security check:
    if (!getSecurityHandler().validateMenuItemCreate(user, siteKey.toInt(),
            parentKey == null ? -1 : parentKey.toInt())) {
        VerticalEngineLogger.errorSecurity(this.getClass(), 10,
                "Not allowed to create menuitem in this position.", null);
    }// w  w w .j a  va 2s  .c  o m

    String menuItemName = XMLTool
            .getElementText(XMLTool.getElement(menuItemElement, ELEMENT_NAME_MENUITEM_NAME));

    if (StringUtils.isEmpty(menuItemName)) {
        menuItemName = generateMenuItemName(menuItemElement);
    }

    menuItemName = ensureUniqueMenuItemName(siteKey, parentKey, menuItemName, null);

    // check whether name is unique for this parent
    if (menuItemNameExists(siteKey, parentKey, menuItemName, null)) {
        VerticalEngineLogger.errorCreate(this.getClass(), 20, "Menu item name already exists on this level: %0",
                new Object[] { menuItemName }, null);
    }

    Element tmp_element;
    Hashtable<String, Integer> menuItemTypes = getMenuItemTypesAsHashtable();

    // Get menuitem type:
    String miType = menuItemElement.getAttribute("type");
    Integer type = menuItemTypes.get(miType);
    if (type == null) {
        VerticalEngineLogger.errorCreate(this.getClass(), 20, "Invalid menu item type %0.",
                new Object[] { type }, null);
    }

    Connection con = null;
    PreparedStatement preparedStmt = null;
    MenuItemKey menuItemKey = null;

    try {
        con = getConnection();

        // key
        String keyStr = menuItemElement.getAttribute("key");
        if (!useOldKey || keyStr == null || keyStr.length() == 0) {
            try {
                menuItemKey = new MenuItemKey(getNextKey(MENU_ITEM_TABLE));
            } catch (VerticalKeyException e) {
                VerticalEngineLogger.errorCreate(this.getClass(), 30, "Error generating key for tMenuItem.", e);
            }
        } else {
            menuItemKey = new MenuItemKey(keyStr);
        }
        if (copyContext != null) {
            copyContext.putMenuItemKey(Integer.parseInt(keyStr), menuItemKey.toInt());
        }

        String tmp;

        preparedStmt = con.prepareStatement(MENU_ITEM_INSERT);

        preparedStmt.setInt(1, menuItemKey.toInt());

        // element: name
        validateMenuItemName(menuItemName);
        preparedStmt.setString(2, menuItemName);

        // menu key:
        preparedStmt.setInt(3, siteKey.toInt());

        // attribute: menu item type
        preparedStmt.setInt(4, type);

        // parent
        if (parentKey == null) {
            preparedStmt.setNull(5, Types.INTEGER);
        } else {
            preparedStmt.setInt(5, parentKey.toInt());
        }

        // order:
        preparedStmt.setInt(6, order);

        // pre-fetch data element
        Element dataElem = XMLTool.getElement(menuItemElement, "data");

        // element: parameters
        tmp_element = XMLTool.getElement(menuItemElement, "parameters");
        if (tmp_element != null) {
            dataElem.appendChild(tmp_element);
        }

        // alternative name:
        tmp_element = XMLTool.getElement(menuItemElement, ELEMENT_NAME_MENU_NAME);
        if (tmp_element != null) {
            tmp = XMLTool.getElementText(tmp_element);
            preparedStmt.setString(7, tmp);
        } else {
            preparedStmt.setNull(7, Types.VARCHAR);
        }

        // visibility:
        tmp = menuItemElement.getAttribute("visible");
        if ("no".equals(tmp)) {
            preparedStmt.setInt(8, 1);
        } else {
            preparedStmt.setInt(8, 0);
        }

        // description:
        tmp_element = XMLTool.getElement(menuItemElement, "description");
        String data = XMLTool.getElementText(tmp_element);
        if (data != null) {
            StringReader reader = new StringReader(data);
            preparedStmt.setCharacterStream(9, reader, data.length());
        } else {
            preparedStmt.setNull(9, Types.VARCHAR);
        }

        if (type == 4) {
            Element docElem = XMLTool.getElement(menuItemElement, "document");

            if (docElem != null) {
                dataElem.appendChild(docElem);
            }
        }

        // attribute: owner/modifier
        String ownerKey = menuItemElement.getAttribute("owner");
        preparedStmt.setString(10, ownerKey);
        preparedStmt.setString(11, ownerKey);

        // data
        if (dataElem != null) {
            Document dataDoc = XMLTool.createDocument();
            dataDoc.appendChild(dataDoc.importNode(dataElem, true));

            byte[] bytes = XMLTool.documentToBytes(dataDoc, "UTF-8");
            preparedStmt.setBinaryStream(12, new ByteArrayInputStream(bytes), bytes.length);
        } else {
            preparedStmt.setNull(12, Types.BLOB);
        }

        // keywords
        tmp_element = XMLTool.getElement(menuItemElement, "keywords");
        String keywords = XMLTool.getElementText(tmp_element);
        if (keywords == null || keywords.length() == 0) {
            preparedStmt.setNull(13, Types.VARCHAR);
        } else {
            StringReader keywordReader = new StringReader(keywords);
            preparedStmt.setCharacterStream(13, keywordReader, keywords.length());
        }

        // language
        String lanKey = menuItemElement.getAttribute("languagekey");
        if ((lanKey != null) && (lanKey.length() > 0)) {
            preparedStmt.setInt(14, Integer.parseInt(lanKey));
        } else {
            preparedStmt.setNull(14, Types.INTEGER);
        }

        RunAsType runAs = RunAsType.INHERIT;
        String runAsStr = menuItemElement.getAttribute("runAs");
        if (StringUtils.isNotEmpty(runAsStr)) {
            runAs = RunAsType.valueOf(runAsStr);
        }
        preparedStmt.setInt(15, runAs.getKey());

        // Display-name
        String displayName = getElementValue(menuItemElement, ELEMENT_NAME_DISPLAY_NAME);
        preparedStmt.setString(16, displayName);

        // execute statement:
        preparedStmt.executeUpdate();

        // Create type specific data.
        switch (type) {
        case 1:
            // page
            createPage(con, menuItemElement, type, menuItemKey);
            break;

        case 2:
            // URL
            createOrUpdateURL(con, menuItemElement, menuItemKey);
            break;

        case 4:
            // document: nothing
            // page
            Element pageElem = XMLTool.getElement(menuItemElement, "page");
            PageTemplateKey pageTemplateKey = new PageTemplateKey(pageElem.getAttribute("pagetemplatekey"));
            PageTemplateType pageTemplateType = getPageTemplateHandler().getPageTemplateType(pageTemplateKey);
            if (pageTemplateType == PageTemplateType.SECTIONPAGE
                    || pageTemplateType == PageTemplateType.NEWSLETTER) {
                createSection(menuItemElement, menuItemKey);
            }
            createPage(con, menuItemElement, type, menuItemKey);
            break;

        case 5:
            // label
            break;

        case 6:
            // section
            createSection(menuItemElement, menuItemKey);
            break;

        case 7:
            // shortcut
            createOrOverrideShortcut(menuItemElement, menuItemKey);
            break;

        default:
            VerticalEngineLogger.errorCreate(this.getClass(), 70, "Unknown menuitem type: %0",
                    new Object[] { type }, null);
        }

        // set contentkey if present
        String contentKeyStr = menuItemElement.getAttribute("contentkey");
        if (contentKeyStr.length() == 0) {
            contentKeyStr = "-1";
        }
        setMenuItemContentKey(menuItemKey, Integer.parseInt(contentKeyStr));

        // fire event
        if (multicaster.hasListeners() && copyContext == null) {
            MenuHandlerEvent e = new MenuHandlerEvent(user, siteKey.toInt(), menuItemKey.toInt(), menuItemName,
                    this);
            multicaster.createdMenuItem(e);
        }

        UserSpecification userSpecification = new UserSpecification();
        userSpecification.setDeletedState(UserSpecification.DeletedState.ANY);
        userSpecification.setKey(new UserKey(ownerKey));
        UserEntity owner = userDao.findSingleBySpecification(userSpecification);
        String ownerGroupKey = null;
        if (owner.getUserGroup() != null) {
            ownerGroupKey = owner.getUserGroup().getGroupKey().toString();
        }

        getSecurityHandler().inheritMenuItemAccessRights(siteKey.toInt(),
                parentKey == null ? -1 : parentKey.toInt(), menuItemKey.toInt(), ownerGroupKey);

        // Create other
        Element menuItemsElement = XMLTool.getElement(menuItemElement, "menuitems");
        if (menuItemsElement != null) {
            Element[] elems = XMLTool.getElements(menuItemsElement);
            for (int i = 0; i < elems.length; i++) {
                createMenuItem(user, copyContext, elems[i], siteKey, i, menuItemKey, useOldKey);
            }
        }
    } catch (SQLException e) {
        VerticalEngineLogger.errorCreate(this.getClass(), 40, "A database error occurred: %t", e);
    } finally {
        close(preparedStmt);
        close(con);
    }

    return menuItemKey.toInt();
}

From source file:org.wso2.carbon.dataservices.core.odata.RDBMSDataHandler.java

private ODataDataType getODataDataType(int columnType) {
    ODataDataType dataType;/* w w  w. jav a 2  s .c  om*/
    switch (columnType) {
    case Types.INTEGER:
        dataType = ODataDataType.INT32;
        break;
    case Types.TINYINT:
        /* fall through */
    case Types.SMALLINT:
        dataType = ODataDataType.INT16;
        break;
    case Types.DOUBLE:
        dataType = ODataDataType.DOUBLE;
        break;
    case Types.VARCHAR:
        /* fall through */
    case Types.CHAR:
        /* fall through */
    case Types.LONGVARCHAR:
        /* fall through */
    case Types.CLOB:
        /* fall through */
    case Types.LONGNVARCHAR:
        /* fall through */
    case Types.NCHAR:
        /* fall through */
    case Types.NVARCHAR:
        /* fall through */
    case Types.NCLOB:
        /* fall through */
    case Types.SQLXML:
        dataType = ODataDataType.STRING;
        break;
    case Types.BOOLEAN:
        /* fall through */
    case Types.BIT:
        dataType = ODataDataType.BOOLEAN;
        break;
    case Types.BLOB:
        /* fall through */
    case Types.BINARY:
        /* fall through */
    case Types.LONGVARBINARY:
        /* fall through */
    case Types.VARBINARY:
        dataType = ODataDataType.BINARY;
        break;
    case Types.DATE:
        dataType = ODataDataType.DATE;
        break;
    case Types.DECIMAL:
        /* fall through */
    case Types.NUMERIC:
        dataType = ODataDataType.DECIMAL;
        break;
    case Types.FLOAT:
        /* fall through */
    case Types.REAL:
        dataType = ODataDataType.SINGLE;
        break;
    case Types.TIME:
        dataType = ODataDataType.TIMEOFDAY;
        break;
    case Types.BIGINT:
        dataType = ODataDataType.INT64;
        break;
    case Types.TIMESTAMP:
        dataType = ODataDataType.DATE_TIMEOFFSET;
        break;
    default:
        dataType = ODataDataType.STRING;
        break;
    }
    return dataType;
}

From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatUtilities.java

public static String sqlTypeString(int sqlType) {
    switch (sqlType) {
    case Types.BIT:
        return "BIT";
    case Types.TINYINT:
        return "TINYINT";
    case Types.SMALLINT:
        return "SMALLINT";
    case Types.INTEGER:
        return "INTEGER";
    case Types.BIGINT:
        return "BIGINT";
    case Types.FLOAT:
        return "FLOAT";
    case Types.REAL:
        return "REAL";
    case Types.DOUBLE:
        return "DOUBLE";
    case Types.NUMERIC:
        return "NUMERIC";
    case Types.DECIMAL:
        return "DECIMAL";
    case Types.CHAR:
        return "CHAR";
    case Types.VARCHAR:
        return "VARCHAR";
    case Types.LONGVARCHAR:
        return "LONGVARCHAR";
    case Types.DATE:
        return "DATE";
    case Types.TIME:
        return "TIME";
    case Types.TIMESTAMP:
        return "TIMESTAMP";
    case Types.BINARY:
        return "BINARY";
    case Types.VARBINARY:
        return "VARBINARY";
    case Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case Types.NULL:
        return "NULL";
    case Types.OTHER:
        return "OTHER";
    case Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case Types.DISTINCT:
        return "DISTINCT";
    case Types.STRUCT:
        return "STRUCT";
    case Types.ARRAY:
        return "ARRAY";
    case Types.BLOB:
        return "BLOB";
    case Types.CLOB:
        return "CLOB";
    case Types.REF:
        return "REF";
    case Types.DATALINK:
        return "DATALINK";
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.ROWID:
        return "ROWID";
    case Types.NCHAR:
        return "NCHAR";
    case Types.NVARCHAR:
        return "NVARCHAR";
    case Types.LONGNVARCHAR:
        return "LONGNVARCHAR";
    case Types.NCLOB:
        return "NCLOB";
    case Types.SQLXML:
        return "SQLXML";
    default:/*from w  w  w .j  a v a2s .  c o  m*/
        return "<UNKNOWN>";
    }
}

From source file:com.feedzai.commons.sql.abstraction.engine.AbstractDatabaseEngine.java

/**
 * Maps the database type to {@link DbColumnType}. If there's no mapping a {@link DbColumnType#UNMAPPED} is returned.
 *
 * @param type The SQL type from {@link java.sql.Types}.
 * @return The {@link DbColumnType}./*from  w w w  .  ja v a  2s .  com*/
 */
protected DbColumnType toPdbType(final int type) {
    switch (type) {
    case Types.ARRAY:
        return DbColumnType.UNMAPPED;
    case Types.BIGINT:
        return DbColumnType.LONG;
    case Types.BINARY:
        return DbColumnType.BLOB;
    case Types.BIT:
        return DbColumnType.BOOLEAN;
    case Types.BLOB:
        return DbColumnType.BLOB;
    case Types.BOOLEAN:
        return DbColumnType.BOOLEAN;
    case Types.CHAR:
        return DbColumnType.STRING;
    case Types.CLOB:
        return DbColumnType.STRING;
    case Types.DATALINK:
        return DbColumnType.UNMAPPED;
    case Types.DATE:
        return DbColumnType.UNMAPPED;
    case Types.DECIMAL:
        return DbColumnType.DOUBLE;
    case Types.DISTINCT:
        return DbColumnType.UNMAPPED;
    case Types.DOUBLE:
        return DbColumnType.DOUBLE;
    case Types.FLOAT:
        return DbColumnType.DOUBLE;
    case Types.INTEGER:
        return DbColumnType.INT;
    case Types.JAVA_OBJECT:
        return DbColumnType.BLOB;
    case Types.LONGNVARCHAR:
        return DbColumnType.STRING;
    case Types.LONGVARBINARY:
        return DbColumnType.BLOB;
    case Types.LONGVARCHAR:
        return DbColumnType.STRING;
    case Types.NCHAR:
        return DbColumnType.STRING;
    case Types.NCLOB:
        return DbColumnType.STRING;
    case Types.NULL:
        return DbColumnType.UNMAPPED;
    case Types.NUMERIC:
        return DbColumnType.DOUBLE;
    case Types.NVARCHAR:
        return DbColumnType.STRING;
    case Types.OTHER:
        return DbColumnType.UNMAPPED;
    case Types.REAL:
        return DbColumnType.DOUBLE;
    case Types.REF:
        return DbColumnType.UNMAPPED;
    case Types.ROWID:
        return DbColumnType.STRING;
    case Types.SMALLINT:
        return DbColumnType.INT;
    case Types.SQLXML:
        return DbColumnType.STRING;
    case Types.STRUCT:
        return DbColumnType.UNMAPPED;
    case Types.TIME:
        return DbColumnType.UNMAPPED;
    case Types.TIMESTAMP:
        return DbColumnType.LONG;
    case Types.TINYINT:
        return DbColumnType.INT;
    case Types.VARBINARY:
        return DbColumnType.BLOB;
    case Types.VARCHAR:
        return DbColumnType.STRING;
    default:
        return DbColumnType.UNMAPPED;
    }
}

From source file:it.greenvulcano.gvesb.datahandling.dbo.DBOCallSP.java

/**
 * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
 *      java.lang.String, java.lang.String)
 *//*  w  w  w.j  ava 2 s . c  o  m*/
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (ROW_NAME.equals(localName)) {
        if (!currCriticalError) {
            executeStatement();
        } else {
            rowDisc++;
            // aggiunta DiscardCause al dhr...
            String msg = currentXSLMessage;

            dhr.addDiscardCause(new DiscardCause(rowCounter, msg));

            resultMessage.append("Data error on row ").append(rowCounter).append(": ").append(msg);
            resultMessage.append("SQL Statement Informations:\n").append(sqlStatementInfo);
            resultMessage.append("Record parameters:\n").append(dumpCurrentRowFields());
            resultStatus = STATUS_PARTIAL;
        }
    } else if (COL_NAME.equals(localName)) {
        CallableStatement cs = (CallableStatement) sqlStatementInfo.getStatement();
        try {
            if (!outOnly) {
                colDataExpecting = false;
                String text = textBuffer.toString();
                if ((currentUUID != null) && (currentUUID.trim().length() > 0) && (text.length() == 0)) {
                    text = uuids.get(currentUUID);
                    if (text == null) {
                        text = currentUUID;
                    }
                }
                if (TIMESTAMP_TYPE.equals(currType) || DATE_TYPE.equals(currType)
                        || TIME_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (TIMESTAMP_TYPE.equals(currType))
                            setNull(cs, Types.TIMESTAMP);
                        else if (DATE_TYPE.equals(currType))
                            setNull(cs, Types.DATE);
                        else
                            setNull(cs, Types.TIME);
                        currentRowFields.add(null);
                    } else {
                        dateFormatter.applyPattern(currDateFormat);
                        Date formattedDate = dateFormatter.parse(text);
                        if (TIMESTAMP_TYPE.equals(currType)) {
                            Timestamp ts = new Timestamp(formattedDate.getTime());
                            setTimestamp(cs, ts);
                            currentRowFields.add(ts);
                        } else if (DATE_TYPE.equals(currType)) {
                            java.sql.Date d = new java.sql.Date(formattedDate.getTime());
                            setDate(cs, d);
                            currentRowFields.add(d);
                        } else {
                            java.sql.Time t = new java.sql.Time(formattedDate.getTime());
                            setTime(cs, t);
                            currentRowFields.add(t);
                        }
                    }
                } else if (INTEGER_TYPE.equals(currType) || SMALLINT_TYPE.equals(currType)
                        || BIGINT_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (INTEGER_TYPE.equals(currType))
                            setNull(cs, Types.INTEGER);
                        else if (SMALLINT_TYPE.equals(currType))
                            setNull(cs, Types.SMALLINT);
                        else
                            setNull(cs, Types.BIGINT);
                        currentRowFields.add(null);
                    } else {
                        if (INTEGER_TYPE.equals(currType))
                            setInt(cs, Integer.parseInt(text, 10));
                        else if (SMALLINT_TYPE.equals(currType))
                            setShort(cs, Short.parseShort(text, 10));
                        else
                            setLong(cs, Long.parseLong(text, 10));
                        currentRowFields.add(text);
                    }
                } else if (FLOAT_TYPE.equals(currType) || DOUBLE_TYPE.equals(currType)
                        || DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType))
                            setNull(cs, Types.NUMERIC);
                        else if (FLOAT_TYPE.equals(currType))
                            setNull(cs, Types.FLOAT);
                        else
                            setNull(cs, Types.DOUBLE);
                        currentRowFields.add(null);
                    } else {
                        DecimalFormatSymbols dfs = numberFormatter.getDecimalFormatSymbols();
                        dfs.setDecimalSeparator(currDecSeparator.charAt(0));
                        dfs.setGroupingSeparator(currGroupSeparator.charAt(0));
                        numberFormatter.setDecimalFormatSymbols(dfs);
                        numberFormatter.applyPattern(currNumberFormat);
                        boolean isBigDecimal = numberFormatter.isParseBigDecimal();
                        try {
                            numberFormatter.setParseBigDecimal(true);
                            BigDecimal formattedNumber = (BigDecimal) numberFormatter.parse(text);
                            if (DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType)) {
                                setBigDecimal(cs, formattedNumber);
                                currentRowFields.add(formattedNumber);
                            } else if (FLOAT_TYPE.equals(currType)) {
                                setFloat(cs, formattedNumber.floatValue());
                                currentRowFields.add(formattedNumber.floatValue());
                            } else {
                                setDouble(cs, formattedNumber.doubleValue());
                                currentRowFields.add(formattedNumber.doubleValue());
                            }
                        } finally {
                            numberFormatter.setParseBigDecimal(isBigDecimal);
                        }
                    }
                } else if (LONG_STRING_TYPE.equals(currType) || LONG_NSTRING_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (LONG_STRING_TYPE.equals(currType))
                            setNull(cs, Types.CLOB);
                        else
                            setNull(cs, Types.NCLOB);
                        currentRowFields.add(null);
                    } else {
                        if (LONG_STRING_TYPE.equals(currType)) {
                            setCharacterStream(cs, new StringReader(text));
                            currentRowFields.add(text);
                        } else {
                            setNCharacterStream(cs, new StringReader(text));
                            currentRowFields.add(text);
                        }
                    }
                } else if (BASE64_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BLOB);
                        currentRowFields.add(null);
                    } else {
                        byte[] data = text.getBytes();
                        data = Base64.getDecoder().decode(data);
                        ByteArrayInputStream bais = new ByteArrayInputStream(data);
                        setBinaryStream(cs, bais, data.length);
                        currentRowFields.add(text);
                    }
                } else if (BINARY_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BLOB);
                        currentRowFields.add(null);
                    } else {
                        byte[] data = text.getBytes();
                        ByteArrayInputStream bais = new ByteArrayInputStream(data);
                        setBinaryStream(cs, bais, data.length);
                        currentRowFields.add(text);
                    }
                } else if (BOOLEAN_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BOOLEAN);
                        currentRowFields.add(null);
                    } else {
                        setBoolean(cs, TextUtils.parseBoolean(text));
                        currentRowFields.add(text);
                    }
                } else if (XML_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.SQLXML);
                        currentRowFields.add(null);
                    } else {
                        SQLXML xml = cs.getConnection().createSQLXML();
                        xml.setString(text);
                        setSQLXML(cs, xml);
                        currentRowFields.add(text);
                    }
                } else if (NSTRING_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.NVARCHAR);
                        currentRowFields.add(null);
                    } else {
                        setNString(cs, text);
                        currentRowFields.add(text);
                    }
                } else {
                    if (text.equals("")) {
                        setNull(cs, Types.VARCHAR);
                        currentRowFields.add(null);
                    } else {
                        setString(cs, text);
                        currentRowFields.add(text);
                    }
                }
            } else {
                currentRowFields.add(currentUUID);
            }
        } catch (ParseException exc) {
            throw new SAXException(exc);
        } catch (SQLException exc) {
            OracleExceptionHandler.handleSQLException(exc);
            throw new SAXException(exc);
        }
    }
}