Example usage for java.sql Types TIME

List of usage examples for java.sql Types TIME

Introduction

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

Prototype

int TIME

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

Click Source Link

Document

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

Usage

From source file:org.apache.phoenix.pig.util.TypeUtil.java

/**
 * This method encodes a value with Phoenix data type. It begins with checking whether an object is BINARY and makes
 * a call to {@link #castBytes(Object, PDataType)} to convert bytes to targetPhoenixType. It returns a {@link RuntimeException}
 * when object can not be coerced.//from   w w w  .ja  v  a 2s .co  m
 * 
 * @param o
 * @param targetPhoenixType
 * @return Object
 */
public static Object castPigTypeToPhoenix(Object o, byte objectType, PDataType targetPhoenixType) {
    PDataType inferredPType = getType(o, objectType);

    if (inferredPType == null) {
        return null;
    }

    if (inferredPType == PVarbinary.INSTANCE) {
        try {
            o = castBytes(o, targetPhoenixType);
            if (targetPhoenixType != PVarbinary.INSTANCE && targetPhoenixType != PBinary.INSTANCE) {
                inferredPType = getType(o, DataType.findType(o));
            }
        } catch (IOException e) {
            throw new RuntimeException("Error while casting bytes for object " + o);
        }
    }
    if (inferredPType == PDate.INSTANCE) {
        int inferredSqlType = targetPhoenixType.getSqlType();

        if (inferredSqlType == Types.DATE) {
            return new Date(((DateTime) o).getMillis());
        }
        if (inferredSqlType == Types.TIME) {
            return new Time(((DateTime) o).getMillis());
        }
        if (inferredSqlType == Types.TIMESTAMP) {
            return new Timestamp(((DateTime) o).getMillis());
        }
    }

    if (targetPhoenixType == inferredPType || inferredPType.isCoercibleTo(targetPhoenixType)) {
        return inferredPType.toObject(o, targetPhoenixType);
    }

    throw new RuntimeException(
            o.getClass().getName() + " cannot be coerced to " + targetPhoenixType.toString());
}

From source file:org.executequery.gui.resultset.ResultSetTableModel.java

public void createTable(ResultSet resultSet) {

    if (!isOpenAndValid(resultSet)) {

        clearData();//from  w  w  w .j  av  a 2  s .  co m
        return;
    }

    try {

        resetMetaData();
        ResultSetMetaData rsmd = resultSet.getMetaData();

        columnHeaders.clear();
        visibleColumnHeaders.clear();
        tableData.clear();

        int zeroBaseIndex = 0;
        int count = rsmd.getColumnCount();
        for (int i = 1; i <= count; i++) {

            zeroBaseIndex = i - 1;

            columnHeaders.add(new ResultSetColumnHeader(zeroBaseIndex, rsmd.getColumnLabel(i),
                    rsmd.getColumnName(i), rsmd.getColumnType(i), rsmd.getColumnTypeName(i)));
        }

        int recordCount = 0;
        interrupted = false;

        if (holdMetaData) {

            setMetaDataVectors(rsmd);
        }

        List<RecordDataItem> rowData;
        long time = System.currentTimeMillis();
        while (resultSet.next()) {

            if (interrupted || Thread.interrupted()) {

                throw new InterruptedException();
            }

            recordCount++;
            rowData = new ArrayList<RecordDataItem>(count);

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

                zeroBaseIndex = i - 1;

                ResultSetColumnHeader header = columnHeaders.get(zeroBaseIndex);
                RecordDataItem value = recordDataItemFactory.create(header);

                try {

                    int dataType = header.getDataType();
                    switch (dataType) {

                    // some drivers (informix for example)
                    // was noticed to return the hashcode from
                    // getObject for -1 data types (eg. longvarchar).
                    // force string for these - others stick with
                    // getObject() for default value formatting

                    case Types.CHAR:
                    case Types.VARCHAR:
                        value.setValue(resultSet.getString(i));
                        break;
                    case Types.DATE:
                        value.setValue(resultSet.getDate(i));
                        break;
                    case Types.TIME:
                        value.setValue(resultSet.getTime(i));
                        break;
                    case Types.TIMESTAMP:
                        value.setValue(resultSet.getTimestamp(i));
                        break;
                    case Types.LONGVARCHAR:
                    case Types.CLOB:
                        value.setValue(resultSet.getClob(i));
                        break;
                    case Types.LONGVARBINARY:
                    case Types.VARBINARY:
                    case Types.BINARY:
                        value.setValue(resultSet.getBytes(i));
                        break;
                    case Types.BLOB:
                        value.setValue(resultSet.getBlob(i));
                        break;
                    case Types.BIT:
                    case Types.TINYINT:
                    case Types.SMALLINT:
                    case Types.INTEGER:
                    case Types.BIGINT:
                    case Types.FLOAT:
                    case Types.REAL:
                    case Types.DOUBLE:
                    case Types.NUMERIC:
                    case Types.DECIMAL:
                    case Types.NULL:
                    case Types.OTHER:
                    case Types.JAVA_OBJECT:
                    case Types.DISTINCT:
                    case Types.STRUCT:
                    case Types.ARRAY:
                    case Types.REF:
                    case Types.DATALINK:
                    case Types.BOOLEAN:
                    case Types.ROWID:
                    case Types.NCHAR:
                    case Types.NVARCHAR:
                    case Types.LONGNVARCHAR:
                    case Types.NCLOB:
                    case Types.SQLXML:

                        // use getObject for all other known types

                        value.setValue(resultSet.getObject(i));
                        break;

                    default:

                        // otherwise try as string

                        asStringOrObject(value, resultSet, i);
                        break;
                    }

                } catch (Exception e) {

                    try {

                        // ... and on dump, resort to string
                        value.setValue(resultSet.getString(i));

                    } catch (SQLException sqlException) {

                        // catch-all SQLException - yes, this is hideous

                        // noticed with invalid date formatted values in mysql

                        value.setValue("<Error - " + sqlException.getMessage() + ">");
                    }
                }

                if (resultSet.wasNull()) {

                    value.setNull();
                }

                rowData.add(value);
            }

            tableData.add(rowData);

            if (recordCount == maxRecords) {

                break;
            }

        }

        if (Log.isTraceEnabled()) {

            Log.trace("Finished populating table model - " + recordCount + " rows - [ "
                    + MiscUtils.formatDuration(System.currentTimeMillis() - time) + "]");
        }

        fireTableStructureChanged();

    } catch (SQLException e) {

        System.err.println("SQL error populating table model at: " + e.getMessage());
        Log.debug("Table model error - " + e.getMessage(), e);

    } catch (Exception e) {

        if (e instanceof InterruptedException) {

            Log.debug("ResultSet generation interrupted.", e);

        } else {

            String message = e.getMessage();
            if (StringUtils.isBlank(message)) {

                System.err.println("Exception populating table model.");

            } else {

                System.err.println("Exception populating table model at: " + message);
            }

            Log.debug("Table model error - ", e);
        }

    } finally {

        if (resultSet != null) {

            try {

                resultSet.close();

                Statement statement = resultSet.getStatement();
                if (statement != null) {

                    statement.close();
                }

            } catch (SQLException e) {
            }

        }
    }

}

From source file:org.syncope.core.util.ImportExport.java

private void setParameters(final String tableName, final Attributes atts, final Query query) {

    Map<String, Integer> colTypes = new HashMap<String, Integer>();

    Connection conn = DataSourceUtils.getConnection(dataSource);
    ResultSet rs = null;/*w w w  .  j  av a  2  s  . c  o m*/
    Statement stmt = null;
    try {
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT * FROM " + tableName);
        for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
            colTypes.put(rs.getMetaData().getColumnName(i + 1).toUpperCase(),
                    rs.getMetaData().getColumnType(i + 1));
        }
    } catch (SQLException e) {
        LOG.error("While", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                LOG.error("While closing statement", e);
            }
        }
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                LOG.error("While closing result set", e);
            }
        }
        DataSourceUtils.releaseConnection(conn, dataSource);
    }

    for (int i = 0; i < atts.getLength(); i++) {
        Integer colType = colTypes.get(atts.getQName(i).toUpperCase());
        if (colType == null) {
            LOG.warn("No column type found for {}", atts.getQName(i).toUpperCase());
            colType = Types.VARCHAR;
        }

        switch (colType) {
        case Types.NUMERIC:
        case Types.REAL:
        case Types.INTEGER:
        case Types.TINYINT:
            try {
                query.setParameter(i + 1, Integer.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Integer '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.DECIMAL:
        case Types.BIGINT:
            try {
                query.setParameter(i + 1, Long.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Long '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.DOUBLE:
            try {
                query.setParameter(i + 1, Double.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Double '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.FLOAT:
            try {
                query.setParameter(i + 1, Float.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Float '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            try {
                query.setParameter(i + 1, DateUtils.parseDate(atts.getValue(i), SyncopeConstants.DATE_PATTERNS),
                        TemporalType.TIMESTAMP);
            } catch (ParseException e) {
                LOG.error("Unparsable Date '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.BIT:
        case Types.BOOLEAN:
            query.setParameter(i + 1, "1".equals(atts.getValue(i)) ? Boolean.TRUE : Boolean.FALSE);
            break;

        default:
            query.setParameter(i + 1, atts.getValue(i));
        }
    }
}

From source file:org.apache.syncope.core.util.ContentExporter.java

private String getValues(final ResultSet rs, final String columnName, final Integer columnType)
        throws SQLException {

    String res = null;/*from  ww w. j a va2 s .c  om*/

    try {
        switch (columnType) {
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            final InputStream is = rs.getBinaryStream(columnName);
            if (is != null) {
                res = new String(Hex.encode(IOUtils.toByteArray(is)));
            }
            break;

        case Types.BLOB:
            final Blob blob = rs.getBlob(columnName);
            if (blob != null) {
                res = new String(Hex.encode(IOUtils.toByteArray(blob.getBinaryStream())));
            }
            break;

        case Types.BIT:
        case Types.BOOLEAN:
            if (rs.getBoolean(columnName)) {
                res = "1";
            } else {
                res = "0";
            }
            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            final Timestamp timestamp = rs.getTimestamp(columnName);
            if (timestamp != null) {
                res = DataFormat.format(new Date(timestamp.getTime()));
            }
            break;

        default:
            res = rs.getString(columnName);
        }
    } catch (IOException e) {
        LOG.error("Error retrieving hexadecimal string", e);
    }

    return res;
}

From source file:com.btobits.automator.ant.sql.task.SQLCompareTask.java

private void verify() throws Exception {
    final LinkedList<SQLCompareTask.VerifyCell> rows = impl.getVerifySqls();
    for (final SQLCompareTask.VerifyCell sqlRow : rows) {
        sqlRow.validate();//  w  w w . j a  v a  2  s  . co m

        switch (getColumnType(sqlRow)) {
        case Types.DOUBLE: {
            final Double val = (Double) getRowValue(sqlRow);

            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final DoubleValidator doubleValidator = new DoubleValidator();
            if (doubleValidator.isValid(sqlRow.getValue())) {
                final Double dbValue = doubleValidator.validate(sqlRow.getValue());
                if (!dbValue.equals(val)) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Double value.");
            }
        }
            break;

        case Types.FLOAT: {
            final Float val = (Float) getRowValue(sqlRow);

            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final FloatValidator validator = new FloatValidator();
            if (validator.isValid(sqlRow.getValue())) {
                final Float dbValue = validator.validate(sqlRow.getValue());
                if (!dbValue.equals(val)) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Float value.");
            }
        }
            break;

        case Types.DECIMAL: {
            final BigDecimal val = (BigDecimal) getRowValue(sqlRow);

            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final BigDecimalValidator validator = new BigDecimalValidator();
            if (validator.isValid(sqlRow.getValue())) {
                BigDecimal dbValue = validator.validate(sqlRow.getValue());
                dbValue = dbValue.setScale(val.scale());
                if (!dbValue.equals(val)) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Decimal value.");
            }
        }
            break;

        case Types.DATE: {
            final Date val = (Date) getDateRowValue(sqlRow);

            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final DateValidator validator = DateValidator.getInstance();
            if (validator.isValid(sqlRow.getValue(), "yyyy-MM-dd")) {
                final Date dbValue = validator.validate(sqlRow.getValue(), "yyyy-MM-dd");
                if (!dbValue.equals(val)) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Date value.");
            }
        }
            break;

        case Types.TIME: {
            final Date val = (Date) getTimeRowValue(sqlRow);
            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final TimeValidator validator = TimeValidator.getInstance();
            if (validator.isValid(sqlRow.getValue(), "HH:mm:ss")) {
                final Calendar dbValue = validator.validate(sqlRow.getValue(), "HH:mm:ss");
                final Calendar dbVal = Calendar.getInstance();
                dbVal.setTime(val);

                if (validator.compareHours(dbValue, dbVal) != 0 || validator.compareMinutes(dbValue, dbVal) != 0
                        || validator.compareSeconds(dbValue, dbVal) != 0) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Time value.");
            }
        }
            break;

        case Types.TIMESTAMP: {
            final Date val = getDateTimeRowValue(sqlRow);
            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final CalendarValidator validatorDate = CalendarValidator.getInstance();
            final TimeValidator validatorTime = TimeValidator.getInstance();
            if (validatorDate.isValid(sqlRow.getValue(), "yyyy-MM-dd HH:mm:ss")) {
                final Calendar dbValue = validatorDate.validate(sqlRow.getValue(), "yyyy-MM-dd HH:mm:ss");
                final Calendar dbVal = Calendar.getInstance();
                dbVal.setTimeInMillis(val.getTime());
                if (validatorDate.compareDates(dbVal, dbValue) != 0
                        || validatorTime.compareHours(dbValue, dbVal) != 0
                        || validatorTime.compareMinutes(dbValue, dbVal) != 0
                        || validatorTime.compareSeconds(dbValue, dbVal) != 0) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Timestamp value.");
            }
        }
            break;

        default: {
            final String dbValue = getStringRowValue(sqlRow);
            if (dbValue == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            } else if (!StringUtils.equals(sqlRow.getValue(), dbValue)) {
                errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                        + "], value [" + sqlRow.getValue() + " != " + dbValue + "]");
            }
        }
        }
    }
}

From source file:org.apache.syncope.core.util.ImportExport.java

private void setParameters(final String tableName, final Attributes attrs, final Query query) {

    Map<String, Integer> colTypes = new HashMap<String, Integer>();

    final Table table = getTable(tableName);

    for (int i = 0; i < attrs.getLength(); i++) {
        Integer colType = table.getColumn(QualifiedDBIdentifier.newColumn(attrs.getQName(i))).getType();
        if (colType == null) {
            LOG.warn("No column type found for {}", attrs.getQName(i).toUpperCase());
            colType = Types.VARCHAR;
        }/* w  w w.  ja v a 2  s .c om*/

        switch (colType) {
        case Types.INTEGER:
        case Types.TINYINT:
        case Types.SMALLINT:
            try {
                query.setParameter(i + 1, Integer.valueOf(attrs.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Integer '{}'", attrs.getValue(i));
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.NUMERIC:
        case Types.DECIMAL:
        case Types.BIGINT:
            try {
                query.setParameter(i + 1, Long.valueOf(attrs.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Long '{}'", attrs.getValue(i));
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.DOUBLE:
            try {
                query.setParameter(i + 1, Double.valueOf(attrs.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Double '{}'", attrs.getValue(i));
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.REAL:
        case Types.FLOAT:
            try {
                query.setParameter(i + 1, Float.valueOf(attrs.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Float '{}'", attrs.getValue(i));
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            try {
                query.setParameter(i + 1,
                        DateUtils.parseDate(attrs.getValue(i), SyncopeConstants.DATE_PATTERNS),
                        TemporalType.TIMESTAMP);
            } catch (ParseException e) {
                LOG.error("Unparsable Date '{}'", attrs.getValue(i));
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.BIT:
        case Types.BOOLEAN:
            query.setParameter(i + 1, "1".equals(attrs.getValue(i)) ? Boolean.TRUE : Boolean.FALSE);
            break;

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            try {
                query.setParameter(i + 1, Hex.decode(attrs.getValue(i)));
            } catch (IllegalArgumentException e) {
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.BLOB:
            try {
                query.setParameter(i + 1, Hex.decode(attrs.getValue(i)));
            } catch (IllegalArgumentException e) {
                LOG.warn("Error decoding hex string to specify a blob parameter", e);
                query.setParameter(i + 1, attrs.getValue(i));
            } catch (Exception e) {
                LOG.warn("Error creating a new blob parameter", e);
            }
            break;

        default:
            query.setParameter(i + 1, attrs.getValue(i));
        }
    }
}

From source file:com.squid.core.jdbc.formatter.DefaultJDBCDataFormatter.java

public String getColumnFormat(int colType, int precision, int scale) {
    String stringFormat = null;/*from   www . ja  v a 2 s.co m*/
    switch (colType) {

    case Types.DATE:
        stringFormat = formatter.getDateFormat();
        break;
    case Types.TIME:
        break;
    case Types.TIMESTAMP:
        stringFormat = formatter.getTimestampFormat();
        break;
    }
    return stringFormat;
}

From source file:org.jfree.data.jdbc.JDBCPieDataset.java

/**
 *  ExecuteQuery will attempt execute the query passed to it against the
 *  existing database connection.  If no connection exists then no action
 *  is taken./*from ww w  .ja  v a  2 s.c om*/
 *  The results from the query are extracted and cached locally, thus
 *  applying an upper limit on how many rows can be retrieved successfully.
 *
 * @param  query  the query to be executed
 * @param  con  the connection the query is to be executed against
 *
 * @throws SQLException if there is a problem executing the query.
 */
public void executeQuery(Connection con, String query) throws SQLException {

    Statement statement = null;
    ResultSet resultSet = null;

    try {
        statement = con.createStatement();
        resultSet = statement.executeQuery(query);
        ResultSetMetaData metaData = resultSet.getMetaData();

        int columnCount = metaData.getColumnCount();
        if (columnCount != 2) {
            throw new SQLException("Invalid sql generated.  PieDataSet requires 2 columns only");
        }

        int columnType = metaData.getColumnType(2);
        double value = Double.NaN;
        while (resultSet.next()) {
            Comparable key = resultSet.getString(1);
            switch (columnType) {
            case Types.NUMERIC:
            case Types.REAL:
            case Types.INTEGER:
            case Types.DOUBLE:
            case Types.FLOAT:
            case Types.DECIMAL:
            case Types.BIGINT:
                value = resultSet.getDouble(2);
                setValue(key, value);
                break;

            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                Timestamp date = resultSet.getTimestamp(2);
                value = date.getTime();
                setValue(key, value);
                break;

            default:
                System.err.println("JDBCPieDataset - unknown data type");
                break;
            }
        }

        fireDatasetChanged(new DatasetChangeInfo());
        //TODO: fill in real change info

    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (Exception e) {
                System.err.println("JDBCPieDataset: swallowing exception.");
            }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (Exception e) {
                System.err.println("JDBCPieDataset: swallowing exception.");
            }
        }
    }
}

From source file:org.apache.cocoon.util.JDBCTypeConversions.java

/**
 * Get the Statement column so that the results are mapped correctly.
 * (this has been copied from AbstractDatabaseAction and modified slightly)
 *//*from   w ww .  jav  a2  s.c  om*/
public static Object getColumn(ResultSet set, Configuration column) throws Exception {

    Integer type = (Integer) JDBCTypeConversions.typeConstants.get(column.getAttribute("type"));
    String dbcol = column.getAttribute("name");
    Object value = null;

    switch (type.intValue()) {
    case Types.CLOB:
    case Types.CHAR:
        Clob dbClob = set.getClob(dbcol);
        int length = (int) dbClob.length();
        InputStream asciiStream = new BufferedInputStream(dbClob.getAsciiStream());
        byte[] buffer = new byte[length];
        asciiStream.read(buffer);
        String str = new String(buffer);
        asciiStream.close();
        value = str;
        break;
    case Types.BIGINT:
        value = set.getBigDecimal(dbcol);
        break;
    case Types.TINYINT:
        value = new Byte(set.getByte(dbcol));
        break;
    case Types.VARCHAR:
        value = set.getString(dbcol);
        break;
    case Types.DATE:
        value = set.getDate(dbcol);
        break;
    case Types.DOUBLE:
        value = new Double(set.getDouble(dbcol));
        break;
    case Types.FLOAT:
        value = new Float(set.getFloat(dbcol));
        break;
    case Types.INTEGER:
        value = new Integer(set.getInt(dbcol));
        break;
    case Types.NUMERIC:
        value = new Long(set.getLong(dbcol));
        break;
    case Types.SMALLINT:
        value = new Short(set.getShort(dbcol));
        break;
    case Types.TIME:
        value = set.getTime(dbcol);
        break;
    case Types.TIMESTAMP:
        value = set.getTimestamp(dbcol);
        break;
    case Types.ARRAY:
        value = set.getArray(dbcol); // new Integer(set.getInt(dbcol));
        break;
    case Types.BIT:
        value = BooleanUtils.toBooleanObject(set.getBoolean(dbcol));
        break;
    case Types.STRUCT:
        value = (Struct) set.getObject(dbcol);
        break;
    case Types.OTHER:
        value = set.getObject(dbcol);
        break;

    default:
        // The blob types have to be requested separately, via a Reader.
        value = "";
        break;
    }

    return value;
}

From source file:org.dashbuilder.dataprovider.backend.sql.JDBCUtils.java

public static ColumnType calculateType(int sqlDataType) {
    switch (sqlDataType) {

    // Category-like columns.
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.BIT:
    case Types.BOOLEAN: {
        return ColumnType.LABEL;
    }/*  w ww.j  av a  2s. c o  m*/

    // Text-like columns.
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR: {
        return ColumnType.TEXT;
    }

    // Number-like columns.
    case Types.TINYINT:
    case Types.BIGINT:
    case Types.INTEGER:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.NUMERIC:
    case Types.REAL:
    case Types.SMALLINT: {
        return ColumnType.NUMBER;
    }

    // Date-like columns.
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP: {
        return ColumnType.DATE;
    }

    /*case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
    case Types.NULL:
    case Types.OTHER:
    case Types.JAVA_OBJECT:
    case Types.DISTINCT:
    case Types.STRUCT:
    case Types.ARRAY:
    case Types.BLOB:
    case Types.CLOB:
    case Types.REF:
    case Types.ROWID:
    case Types.SQLXML:
    case Types.DATALINK:*/

    // Unsupported (see above) types are treated as a text values.
    default: {
        return ColumnType.TEXT;
    }
    }
}