Example usage for java.sql Types ARRAY

List of usage examples for java.sql Types ARRAY

Introduction

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

Prototype

int ARRAY

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

Click Source Link

Document

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

Usage

From source file:org.trafodion.rest.util.JdbcT2Util.java

private synchronized JSONArray convertResultSetToJSON(java.sql.ResultSet rs) throws Exception {
    if (LOG.isDebugEnabled())
        LOG.debug("Begin convertResultSetToJSON");

    JSONArray json = new JSONArray();

    try {/*from   w w  w.j a  va  2  s.  c  o  m*/

        java.sql.ResultSetMetaData rsmd = rs.getMetaData();

        while (rs.next()) {
            int numColumns = rsmd.getColumnCount();
            JSONObject obj = new JSONObject();

            for (int i = 1; i < numColumns + 1; i++) {

                String column_name = rsmd.getColumnName(i);

                if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) {
                    obj.put(column_name, rs.getArray(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) {
                    obj.put(column_name, rs.getLong(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) {
                    obj.put(column_name, rs.getBoolean(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) {
                    obj.put(column_name, rs.getBlob(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) {
                    obj.put(column_name, rs.getDouble(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) {
                    obj.put(column_name, rs.getFloat(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) {
                    obj.put(column_name, rs.getInt(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) {
                    obj.put(column_name, rs.getNString(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.CHAR
                        || rsmd.getColumnType(i) == java.sql.Types.VARCHAR) {
                    //prevent obj.put from removing null key value from JSONObject
                    String s = rs.getString(column_name);
                    if (s == null)
                        obj.put(column_name, new String(""));
                    else
                        obj.put(column_name, rs.getString(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) {
                    obj.put(column_name, rs.getInt(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) {
                    obj.put(column_name, rs.getInt(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) {
                    obj.put(column_name, rs.getDate(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) {
                    obj.put(column_name, rs.getTimestamp(column_name));
                } else {
                    obj.put(column_name, rs.getObject(column_name));
                }

            } //end foreach 
            json.put(obj);

        } //end while 

    } catch (SQLException e) {
        e.printStackTrace();
        if (LOG.isDebugEnabled())
            LOG.error(e.getMessage());
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
        if (LOG.isDebugEnabled())
            LOG.error(e.getMessage());
        throw e;
    }

    if (LOG.isDebugEnabled())
        LOG.debug("End convertResultSetToJSON");

    return json;
}

From source file:com.tesora.dve.db.mysql.DBTypeBasedUtilsTest.java

@Test(expected = PEException.class)
public void sqlFailTest() throws Exception {
    DBTypeBasedUtils.getSQLTypeFunc(Types.ARRAY);
}

From source file:org.xsystem.sql2.dml.DmlCommand.java

void setParms(CallableStatement cs, List<DmlParams> paramsSpec, Map<String, Object> values)
        throws SQLException {
    int i = 0;//from   w ww  .j a v a  2s  .co  m
    Connection con = cs.getConnection();
    AbstactNativeHelper nativeHelper = nativeHelperFactory(con);
    for (DmlParams row : paramsSpec) {
        String paramName = row.getName();
        Integer jdbcType = row.getJdbcType();
        String objectType = row.getObjectType();
        Object value = values.get(paramName);
        boolean in = row.isIn();
        boolean out = row.isOut();
        i = i + 1;
        if (in) {
            if (namedParams) {
                if (jdbcType == Types.OTHER) {
                    cs.setObject(paramName, value);
                } else {
                    value = setValue(value, jdbcType, objectType, con, nativeHelper);
                    if (value != null) {
                        value = convert(value, jdbcType);
                        cs.setObject(paramName, value, jdbcType);
                    } else {
                        cs.setNull(paramName, jdbcType);
                    }
                }
            } else {
                if (jdbcType == Types.OTHER) {
                    cs.setObject(i, value);
                } else {
                    if (jdbcType == JdbcTypeMapping.json) {
                        nativeHelper.setJSONPARAM(cs, i, value);
                    } else {
                        value = setValue(value, jdbcType, objectType, con, nativeHelper);

                        if (value != null) {
                            value = convert(value, jdbcType);
                            cs.setObject(i, value, jdbcType);
                        } else {
                            cs.setNull(i, jdbcType);
                        }
                    }
                }
            }
        }
        if (out) {
            if (namedParams) {

                if (jdbcType == Types.ARRAY || jdbcType == Types.STRUCT) {
                    cs.registerOutParameter(paramName, jdbcType, objectType);
                } else {
                    cs.registerOutParameter(paramName, jdbcType);
                }

            } else {
                if (jdbcType == Types.ARRAY || jdbcType == Types.STRUCT) {
                    cs.registerOutParameter(i, jdbcType, objectType);
                } else {
                    cs.registerOutParameter(i, jdbcType);
                }
            }
        }
    }
}

From source file:com.squid.core.domain.operators.ExtendedType.java

private String getTypeName(int SQLType) {
    switch (SQLType) {
    case Types.ARRAY:
        return "ARRAY";
    case Types.BIGINT:
        return "INTEGER";
    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.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.NCHAR:
        return "NCHAR";
    case Types.NCLOB:
        return "NCLOB";
    case Types.NULL:
        return "UNDEFINED";//
    case Types.NUMERIC:
        return "NUMERIC";
    case Types.NVARCHAR:
        return "NVARCHAR";
    case Types.OTHER:
        return "UNDEFINED";//
    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  ww.j  av  a2s.c o m
        return "UNDEFINED";//
    }
}

From source file:com.netspective.axiom.sql.StoredProcedureParameter.java

/**
 * Apply the IN/OUT parameters of the callable statement object
 *
 * @param vac  the context in which the apply action is being performed
 * @param stmt the statement object/*  ww  w  .j  av  a 2  s . c  om*/
 */
public void apply(StoredProcedureParameters.ValueApplyContext vac, ConnectionContext cc, CallableStatement stmt)
        throws SQLException {
    int paramNum = vac.getNextParamNum();
    int jdbcType = getSqlType().getJdbcType();
    if (getType().getValueIndex() == Type.IN || getType().getValueIndex() == Type.IN_OUT) {
        String text = value.getTextValue(cc);
        switch (jdbcType) {
        case Types.VARCHAR:
            // user override value if it exists
            if (vac.hasOverrideValues() && vac.hasActiveParamOverrideValue())
                text = (String) vac.getActiveParamOverrideValue();
            if (allowNull && text == null)
                stmt.setNull(paramNum, Types.VARCHAR);
            else if (text != null)
                stmt.setObject(paramNum, text);
            else
                log.warn("Parameter '" + getName() + "' was not bound. Value = " + text);
            break;

        case Types.CHAR:
            if (vac.hasOverrideValues() && vac.hasActiveParamOverrideValue())
                text = (String) vac.getActiveParamOverrideValue();
            if (allowNull && text == null)
                stmt.setNull(paramNum, Types.CHAR);
            else if (text != null)
                stmt.setObject(paramNum, text.substring(0, 1));
            else
                log.warn("Parameter '" + getName() + "' was not bound. Value = " + text);
            break;

        case Types.INTEGER:
            if (vac.hasOverrideValues() && vac.hasActiveParamOverrideValue())
                text = vac.getActiveParamOverrideValue() != null ? vac.getActiveParamOverrideValue().toString()
                        : null;
            if (allowNull && text == null)
                stmt.setNull(paramNum, Types.INTEGER);
            else if (text != null)
                stmt.setInt(paramNum, Integer.parseInt(text));
            else
                log.warn("Parameter '" + getName() + "' was not bound. Value = " + text);

            break;

        case Types.DOUBLE:
            if (vac.hasOverrideValues() && vac.hasActiveParamOverrideValue())
                text = vac.getActiveParamOverrideValue() != null ? vac.getActiveParamOverrideValue().toString()
                        : null;
            if (allowNull && text == null)
                stmt.setNull(paramNum, Types.DOUBLE);
            else if (text != null)
                stmt.setDouble(paramNum, Double.parseDouble(text));
            else
                log.warn("Parameter '" + getName() + "' was not bound. Value = " + text);

            break;

        case Types.ARRAY:
            // Arrays are quite tricky. Right now, this is supporting String arrays only.
            // TODO: Support integer and float arrays also
            String[] textValues = value.getTextValues(cc);
            if (vac.hasOverrideValues() && vac.hasActiveParamOverrideValue())
                textValues = (String[]) vac.getActiveParamOverrideValue();
            applyInArrayValue(cc, stmt, paramNum, textValues);
            break;
        default:
            log.warn("Unknown JDBC type for parameter '" + getName() + "' (index=" + paramNum
                    + ") of stored procedure '" + parent.getProcedure() + "'.");
            break;
        }
    }
    if (getType().getValueIndex() == Type.OUT || getType().getValueIndex() == Type.IN_OUT) {
        String identifier = getSqlType().getIdentifier();
        // result sets are returned differently for different vendors
        if (identifier.equals(QueryParameterType.RESULTSET_IDENTIFIER))
            stmt.registerOutParameter(paramNum, getVendorSpecificResultSetType(cc));
        else
            stmt.registerOutParameter(paramNum, jdbcType);
    }
}

From source file:org.kawanfw.sql.servlet.sql.ResultSetWriter.java

/**
 * Code extracted and modified for oreilly jdbc book in french.
 * /*w ww . j a  va2 s .co m*/
 * Process the ResultSet and print it on the outPutStream <br>
 * - Each row is a line of a List of column values <br>
 * 
 * @param resultSet
 *            the Result Set to process and print on the output stream
 * @param br
 *            the writer where to redirect the result set content, one Json
 *            line per rs.next();
 * 
 */
public void write(ResultSet resultSet) throws SQLException, IOException {
    try {
        if (resultSet == null) {
            throw new SQLException("SQL Connection is null!");
        }

        String productName = getDatabaseProductName(resultSet);
        isTerradata = productName.equals(SqlUtil.TERADATA) ? true : false;
        isPostgreSQL = productName.equals(SqlUtil.POSTGRESQL) ? true : false;

        ResultSetMetaData meta = resultSet.getMetaData();
        int cols = meta.getColumnCount();

        @SuppressWarnings("unused")
        int row_count = 0;

        List<Integer> columnTypeList = new Vector<Integer>();
        List<String> columnTypeNameList = new Vector<String>();
        List<String> columnNameList = new Vector<String>();
        List<String> columnTableList = new Vector<String>();

        // Loop on Columns
        for (int i = 1; i <= cols; i++) {
            columnTypeList.add(meta.getColumnType(i));
            columnNameList.add(meta.getColumnName(i).toLowerCase());
            columnTypeNameList.add(meta.getColumnTypeName(i));

            if (isPostgreSQL) {
                columnTableList.add(PostgreSqlUtil.getTableName(resultSet, i));
            } else {
                columnTableList.add(meta.getTableName(i));
            }

            debug("");
            debug("meta.getColumnType(" + i + ")    : " + meta.getColumnType(i));
            debug("meta.getColumnTypeName(" + i + "): " + meta.getColumnTypeName(i));
            debug("meta.getColumnName(" + i + ")    : " + meta.getColumnName(i));
            debug("meta.getTableName(" + i + ")     : " + meta.getTableName(i));
        }

        // Ok, dump the column Map<String, Integer> == (Column name, column
        // pos starting 9)
        Map<String, Integer> mapColumnNames = new LinkedHashMap<String, Integer>();

        for (int i = 0; i < columnNameList.size(); i++) {
            mapColumnNames.put(columnNameList.get(i), i);
        }

        String jsonString = JsonColPosition.toJson(mapColumnNames);

        debug("JsonColPosition.toJson(mapColumnNames) jsonString" + jsonString);

        boolean doEncryptResultSet = SqlConfiguratorCall.encryptResultSet(sqlConfigurator);

        // Maybe encryption asked
        if (doEncryptResultSet) {
            jsonString = JsonLineEncrypter.encrypt(jsonString, commonsConfigurator);
        }

        //br.write(jsonString + CR_LF);
        ServerSqlManager.writeLine(out, jsonString);

        // Loop result Set
        while (resultSet.next()) {
            row_count++;

            // The List of column values for one row
            List<String> values = new Vector<String>();

            for (int i = 0; i < columnTypeList.size(); i++) {
                int columnIndex = i + 1;
                int columnType = columnTypeList.get(i);
                String columnName = columnNameList.get(i);
                String columnTable = columnTableList.get(i);

                debug("");
                debug("columnIndex: " + columnIndex);
                debug("columnType : " + columnType);
                debug("columnName : " + columnName);
                debug("columnTable: " + columnTable);

                Object columnValue = null;
                String columnValueStr = null;

                if (isBinaryColumn(resultSet, columnType, columnName, columnTable)) {
                    columnValueStr = formatBinaryColumn(resultSet, columnIndex, columnType, columnName,
                            columnTable);
                } else if (isNStringColumn(columnType)) {
                    columnValueStr = resultSet.getNString(columnIndex);
                    columnValueStr = HtmlConverter.toHtml(columnValueStr);
                } else if (isClobColumn(columnType)) {
                    columnValueStr = formatClobColumn(resultSet, columnIndex);
                } else if (columnType == Types.ARRAY) {
                    columnValueStr = formatArrayColumn(resultSet, columnIndex);
                } else if (columnType == Types.ROWID) {
                    columnValueStr = formatRowIdColumn(resultSet, columnIndex);
                } else {
                    try {
                        columnValue = resultSet.getObject(columnIndex);
                        debug("columnValue: " + columnValue);

                    } catch (Exception e) {
                        // int intValue = resultSet.getInt(columnName);
                        debug("Exception     : " + e.toString());
                        debug("columnType    : " + columnType);
                        debug("columnTypeName: " + columnTypeNameList.get(i));
                        debug("columnName    : " + columnName);
                        throw new SQLException(columnType + "Type/TypeName/ColName " + columnTypeNameList.get(i)
                                + " " + columnName, e);
                    }

                    if (resultSet.wasNull()) {
                        columnValueStr = "NULL";
                    } else if (columnValue == null) {
                        columnValueStr = null;
                    } else {
                        columnValueStr = columnValue.toString();
                    }

                    debug("columnValueStr : " + columnValueStr);

                    // Case we - maybe - have an URL:
                    columnValueStr = urlFormater(resultSet, columnIndex, columnValueStr);

                    if (isCharacterType(columnType)) {
                        debugStringType(columnValueStr);
                        columnValueStr = HtmlConverter.toHtml(columnValueStr);
                    }
                }

                // Add the value to the list of values:
                values.add(columnValueStr);
            }

            jsonString = StringListTransport.toJson(values);
            debug("ResultSetLineTransport.toJson(values) jsonString" + jsonString);

            // Maybe encryption asked
            if (doEncryptResultSet) {
                jsonString = JsonLineEncrypter.encrypt(jsonString, commonsConfigurator);
            }

            //br.write(jsonString + CR_LF);
            ServerSqlManager.writeLine(out, jsonString);

        }

        // Maybe we send also the ResultSet meta data, if asked by client
        // side

        if (JoinResultSetMetaData) {
            //br.write(FileSplitSeparatorLine.RESULT_SET_GET_METADATA_SEP
            //   + CR_LF);
            ServerSqlManager.writeLine(out, FileSplitSeparatorLine.RESULT_SET_GET_METADATA_SEP);

            ResultSetMetaDataWriter resultSetMetaDataWriter = new ResultSetMetaDataWriter(out,
                    commonsConfigurator, sqlConfigurator);
            resultSetMetaDataWriter.write(resultSet);
        }

    } finally {
        // NO! resultSet.close();
        // NO! IOUtils.closeQuietly(br);
    }
}

From source file:com.etcc.csc.dao.OraclePaymentDAO.java

public boolean autoComments(long docId, String docType, String sessionId, String ipAddress, String userId,
        long paymentId, String payerName, double payAmt, String failedFlag, OlcVpsInvoicesRecBean[] invoices,
        OlcUninvoicedViolsRecBean[] uninvoiced) throws EtccException {
    try {//  w  w  w.j  a va 2 s .co m
        setConnection(Util.getDbConnection());
        cstmt = conn.prepareCall("{? = call OLCSC_VPS_COMMENTS.auto_comments(?,?,?,?,?,?,?,?,?,?,?,?)}");

        Map typeMap = new HashMap();
        typeMap.put("TAG_OWNER.OLC_VPS_INVOICES_REC", OlcVpsInvoicesRec.class);
        typeMap.put("TAG_OWNER.OLC_UNINVOICED_VIOLS_REC", OlcUninvoicedViolsRec.class);
        typeMap.put("TAG_OWNER.OLC_ERROR_MSG_REC", ErrorMsgRec.class);
        conn.setTypeMap(typeMap);

        cstmt.registerOutParameter(1, Types.SMALLINT);
        cstmt.setLong(2, docId);
        cstmt.setString(3, docType);
        cstmt.setString(4, sessionId); //session id
        cstmt.setString(5, ipAddress);
        cstmt.setString(6, userId);
        cstmt.setLong(7, paymentId); //payment id
        cstmt.setString(8, payerName);
        cstmt.setDouble(9, payAmt);
        cstmt.setString(10, failedFlag); //

        ArrayDescriptor arraydesc = ArrayDescriptor.createDescriptor("TAG_OWNER.OLC_VPS_INVOICES_ARR", conn);
        ARRAY array = new ARRAY(arraydesc, conn, convertToOracleInvoices(invoices));
        cstmt.setArray(11, array);

        ArrayDescriptor arraydesc1 = ArrayDescriptor.createDescriptor("TAG_OWNER.OLC_UNINVOICED_VIOLS_ARR",
                conn);
        ARRAY array1 = new ARRAY(arraydesc1, conn, convertToOracleUninvoiced(uninvoiced));
        cstmt.setArray(12, array1);

        cstmt.registerOutParameter(13, Types.ARRAY, "TAG_OWNER.OLC_ERROR_MSG_ARR");

        cstmt.execute();

        byte success = cstmt.getByte(1);

        if (success == 0) {
            Collection errors = Util.convertErrorMsgs(cstmt.getArray(9));
            Iterator iter = errors.iterator();
            while (iter.hasNext()) {
                ErrorMessageDTO errorDTO = (ErrorMessageDTO) iter.next();
                logger.info("error occured in autoComments:" + errorDTO.getMessage());
            }
            return false;
        }

        return true;

    } catch (SQLException ex) {
        throw new EtccException();
    } finally {
        closeConnection();
    }
}

From source file:org.sakaiproject.webservices.SakaiReport.java

protected String toJsonString(ResultSet rs) throws SQLException, JSONException {
    ResultSetMetaData rsmd = rs.getMetaData();
    JSONArray array = new JSONArray();
    int numColumns = rsmd.getColumnCount();

    while (rs.next()) {

        JSONObject obj = new JSONObject();
        for (int i = 1; i < numColumns + 1; i++) {

            String column_label = rsmd.getColumnLabel(i);

            LOG.debug("Column Name=" + column_label + ",type=" + rsmd.getColumnType(i));

            switch (rsmd.getColumnType(i)) {
            case Types.ARRAY:
                obj.put(column_label, rs.getArray(i));
                break;
            case Types.BIGINT:
                obj.put(column_label, rs.getInt(i));
                break;
            case Types.BOOLEAN:
                obj.put(column_label, rs.getBoolean(i));
                break;
            case Types.BLOB:
                obj.put(column_label, rs.getBlob(i));
                break;
            case Types.DOUBLE:
                obj.put(column_label, rs.getDouble(i));
                break;
            case Types.FLOAT:
                obj.put(column_label, rs.getFloat(i));
                break;
            case Types.INTEGER:
                obj.put(column_label, rs.getInt(i));
                break;
            case Types.NVARCHAR:
                obj.put(column_label, rs.getNString(i));
                break;
            case Types.VARCHAR:
                obj.put(column_label, rs.getString(i));
                break;
            case Types.TINYINT:
                obj.put(column_label, rs.getInt(i));
                break;
            case Types.SMALLINT:
                obj.put(column_label, rs.getInt(i));
                break;
            case Types.DATE:
                obj.put(column_label, rs.getDate(i));
                break;
            case Types.TIMESTAMP:
                obj.put(column_label, rs.getTimestamp(i));
                break;
            default:
                obj.put(column_label, rs.getObject(i));
                break;
            }//from   w w  w . ja  va2s . com

        }
        array.put(obj);

    }
    return array.toString();
}

From source file:com.squid.core.domain.operators.ExtendedType.java

public static int FromTypeName(String SQLName) {
    if (SQLName.equals("ARRAY")) {
        return Types.ARRAY;
    }//  ww w  . ja v a 2  s.  c  o  m
    if (SQLName.equals("INTEGER")) {
        return Types.INTEGER;
    }
    if (SQLName.equals("BINARY")) {
        return Types.BINARY;
    }
    if (SQLName.equals("BIT")) {
        return Types.BIT;
    }
    if (SQLName.equals("BLOB")) {
        return Types.BLOB;
    }
    if (SQLName.equals("BOOLEAN")) {
        return Types.BOOLEAN;
    }
    if (SQLName.equals("CHAR")) {
        return Types.CHAR;
    }
    if (SQLName.equals("CLOB")) {
        return Types.CLOB;
    }
    if (SQLName.equals("DATALINK")) {
        return Types.DATALINK;
    }
    if (SQLName.equals("DATE")) {
        return Types.DATE;
    }
    if (SQLName.equals("DECIMAL")) {
        return Types.DECIMAL;
    }
    if (SQLName.equals("DOUBLE")) {
        return Types.DOUBLE;
    }
    if (SQLName.equals("FLOAT")) {
        return Types.FLOAT;
    }
    if (SQLName.equals("JAVA_OBJECT")) {
        return Types.JAVA_OBJECT;
    }
    if (SQLName.equals("LONGNVARCHAR")) {
        return Types.LONGNVARCHAR;
    }
    if (SQLName.equals("LONGVARBINARY")) {
        return Types.LONGVARBINARY;
    }
    if (SQLName.equals("NCHAR")) {
        return Types.NCHAR;
    }
    if (SQLName.equals("NCLOB")) {
        return Types.NCLOB;
    }
    if (SQLName.equals("UNDEFINED")) {
        return Types.OTHER;
    }
    if (SQLName.equals("NUMERIC")) {
        return Types.NUMERIC;
    }
    if (SQLName.equals("NVARCHAR")) {
        return Types.NVARCHAR;
    }
    if (SQLName.equals("REAL")) {
        return Types.REAL;
    }
    if (SQLName.equals("REF")) {
        return Types.REF;
    }
    if (SQLName.equals("ROWID")) {
        return Types.ROWID;
    }
    if (SQLName.equals("SMALLINT")) {
        return Types.SMALLINT;
    }
    if (SQLName.equals("SQLXML")) {
        return Types.SQLXML;
    }
    if (SQLName.equals("STRUCT")) {
        return Types.STRUCT;
    }
    if (SQLName.equals("TIME")) {
        return Types.TIME;
    }
    if (SQLName.equals("TIMESTAMP")) {
        return Types.TIMESTAMP;
    }
    if (SQLName.equals("TINYINT")) {
        return Types.TINYINT;
    }
    if (SQLName.equals("VARCHAR")) {
        return Types.VARCHAR;
    }
    if (SQLName.equals("VARBINARY")) {
        return Types.VARBINARY;
    }
    return Types.OTHER;
}

From source file:org.netflux.core.FieldMetadata.java

/**
 * Returns a string representation of the provided type.
 * //  w  ww  .j av  a  2s .c om
 * @param type the type from {@link Types} to transform to a string.
 * @return a string representation of the provided type.
 */
public static String typeToString(int type) {
    switch (type) {
    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.LONGVARBINARY:
        return "LONGVARBINARY";

    case Types.LONGVARCHAR:
        return "LONGVARCHAR";

    case Types.NULL:
        return "NULL";

    case Types.NUMERIC:
        return "NUMERIC";

    case Types.OTHER:
        return "OTHER";

    case Types.REAL:
        return "REAL";

    case Types.REF:
        return "REF";

    case Types.SMALLINT:
        return "SMALLINT";

    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:
        return "*unsupported type*";
    }
}