Example usage for java.sql Types DATE

List of usage examples for java.sql Types DATE

Introduction

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

Prototype

int DATE

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

Click Source Link

Document

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

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 ww .j av  a2 s. c o  m
* @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.seasar.dbflute.logic.replaceschema.loaddata.impl.DfAbsractDataWriter.java

/**
 * Get the bind type to find a value type.
 * @param tableName The name of table corresponding to column. (NotNull)
 * @param columnMeta The meta info of column. (NotNull)
 * @return The type of column. (NullAllowed: However Basically NotNull)
 *//*ww  w .  j a v a2  s .co  m*/
protected Class<?> getBindType(String tableName, DfColumnMeta columnMeta) {
    Map<String, Class<?>> cacheMap = _bindTypeCacheMap.get(tableName);
    if (cacheMap == null) {
        cacheMap = StringKeyMap.createAsFlexibleOrdered();
        _bindTypeCacheMap.put(tableName, cacheMap);
    }
    final String columnName = columnMeta.getColumnName();
    Class<?> bindType = cacheMap.get(columnName);
    if (bindType != null) { // cache hit
        return bindType;
    }

    // use mapped JDBC defined value if found (basically found)
    // because it has already been resolved about JDBC specification per DBMS
    final String jdbcType = _columnHandler.getColumnJdbcType(columnMeta);
    Integer jdbcDefValue = TypeMap.getJdbcDefValueByJdbcType(jdbcType);
    if (jdbcDefValue == null) { // basically no way
        jdbcDefValue = columnMeta.getJdbcDefValue(); // as plain
    }

    // ReplaceSchema uses an own original mapping way
    // (not uses Generate mapping)
    // it's simple mapping (for string processor)
    if (jdbcDefValue == Types.CHAR || jdbcDefValue == Types.VARCHAR || jdbcDefValue == Types.LONGVARCHAR
            || jdbcDefValue == Types.CLOB) {
        bindType = String.class;
    } else if (jdbcDefValue == Types.TINYINT || jdbcDefValue == Types.SMALLINT
            || jdbcDefValue == Types.INTEGER) {
        bindType = Integer.class;
    } else if (jdbcDefValue == Types.BIGINT) {
        bindType = Long.class;
    } else if (jdbcDefValue == Types.DECIMAL || jdbcDefValue == Types.NUMERIC) {
        bindType = BigDecimal.class;
    } else if (jdbcDefValue == Types.TIMESTAMP) {
        bindType = Timestamp.class;
    } else if (jdbcDefValue == Types.TIME) {
        bindType = Time.class;
    } else if (jdbcDefValue == Types.DATE) {
        // it depends on value type settings
        // that which is bound java.sql.Date or java.sql.Timestamp
        bindType = java.util.Date.class;
    } else if (jdbcDefValue == Types.BIT || jdbcDefValue == Types.BOOLEAN) {
        bindType = Boolean.class;
    } else if (jdbcDefValue == Types.BINARY || jdbcDefValue == Types.VARBINARY
            || jdbcDefValue == Types.LONGVARBINARY || jdbcDefValue == Types.BLOB) {
        bindType = byte[].class;
    } else if (jdbcDefValue == Types.OTHER && TypeMap.UUID.equalsIgnoreCase(jdbcType)) {
        // [UUID Headache]: The reason why UUID type has not been supported yet on JDBC.
        bindType = UUID.class;
    } else {
        bindType = Object.class;
    }
    cacheMap.put(columnName, bindType);
    return bindType;
}

From source file:org.akaza.openclinica.dao.managestudy.StudySubjectDAO.java

public EntityBean update(EntityBean eb, Connection con) {
    StudySubjectBean sb = (StudySubjectBean) eb;
    HashMap variables = new HashMap();
    HashMap nullVars = new HashMap();

    // UPDATE study_subject SET LABEL=?, SUBJECT_ID=?, STUDY_ID=?,
    // STATUS_ID=?, ENROLLMENT_DATE=?, DATE_UPDATED=?,
    // UPDATE_ID=?, SECONDARY_LABEL=? WHERE STUDY_SUBJECT_ID=?
    int ind = 1;//w ww.ja  va2s  .c  o m
    variables.put(new Integer(ind), sb.getLabel());
    ind++;
    variables.put(new Integer(ind), new Integer(sb.getSubjectId()));
    ind++;
    variables.put(new Integer(ind), new Integer(sb.getStudyId()));
    ind++;
    variables.put(new Integer(ind), new Integer(sb.getStatus().getId()));
    ind++;
    Date enrollmentDate = sb.getEnrollmentDate();
    if (enrollmentDate == null) {
        nullVars.put(new Integer(ind), new Integer(Types.DATE));
        variables.put(new Integer(ind), null);
        ind++;
    } else {
        variables.put(new Integer(ind), enrollmentDate);
        ind++;
    }
    // date_updated is set to now()
    //  variables.put(new Integer(ind), new java.util.Date());
    //  ind++;
    variables.put(new Integer(ind), new Integer(sb.getUpdater().getId()));
    ind++;
    variables.put(new Integer(ind), sb.getSecondaryLabel());
    ind++;
    if (sb.getTime_zone() == null || sb.getTime_zone().equals("")) {
        nullVars.put(new Integer(ind), new Integer(TypeNames.STRING));
        variables.put(new Integer(ind), "");
    } else {
        variables.put(new Integer(ind), sb.getTime_zone());
    }
    ind++;
    variables.put(new Integer(ind), new Integer(sb.getId()));
    ind++;

    String sql = digester.getQuery("update");
    if (con == null) {
        this.execute(sql, variables, nullVars);
    } else {
        this.execute(sql, variables, nullVars, con);
    }
    return sb;
}

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   w ww .j  ava 2s .co  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:org.siphon.jssql.SqlExecutor.java

private Object translateOutputParameterValue(int sqlType, CallableStatement cs, int index)
        throws SQLException, SqlExecutorException, ScriptException {
    Object obj = cs.getObject(index);
    if (obj == null) {
        return null;
    } else {/*from   w ww  . j a v  a  2 s .c  o m*/
        switch (sqlType) {
        case Types.DATE:
            obj = cs.getDate(index);
        case Types.TIME:
            obj = cs.getTime(index);
        case Types.TIMESTAMP:
            obj = cs.getTimestamp(index);
        }

    }

    Object result = jdbcReturnTypeToJsObject(obj);
    if (result instanceof String) {
        return ((String) result).trim();
    } else {
        return result;
    }
}

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://from   w  w  w .  j a v  a  2s . c o  m
        return "UNKNOWN";
    }
}

From source file:org.agnitas.dao.impl.ImportRecipientsDaoImpl.java

private void setPreparedStatmentForCurrentColumn(PreparedStatement ps, int index, CSVColumnState column,
        ProfileRecipientFields bean, ImportProfile importProfile, ValidatorResults validatorResults)
        throws SQLException {
    String value = Toolkit.getValueFromBean(bean, column.getColName());
    if (column.getType() == CSVColumnState.TYPE_NUMERIC && column.getColName().equals("gender")) {
        if (StringUtils.isEmpty(value) || value == null) {
            ps.setInt(index, 2);//from ww w.jav a  2  s  . co m
        } else {
            if (GenericValidator.isInt(value) && Integer.valueOf(value) <= 5 && Integer.valueOf(value) >= 0) {
                ps.setInt(index, Integer.valueOf(value));
            } else {
                final Integer intValue = importProfile.getGenderMapping().get(value);
                ps.setInt(index, intValue);
            }
        }

    } else if (column.getType() == CSVColumnState.TYPE_CHAR) {
        if (value == null) {
            ps.setNull(index, Types.VARCHAR);
        } else {
            String columnName = column.getColName();
            if (columnName.equals("email")) {
                value = value.toLowerCase();
                if (validatorResults != null
                        && !ImportUtils.checkIsCurrentFieldValid(validatorResults, "email", "checkRange")) {
                    throw new ImportRecipientsToolongValueException(value);
                }
            } else if (importProfile.getKeyColumns().contains(columnName)
                    || (importProfile.getKeyColumns().isEmpty()
                            && columnName.equals(importProfile.getKeyColumn()))) {
                // range validation for keyColumn
                if (validatorResults != null
                        && !ImportUtils.checkIsCurrentFieldValid(validatorResults, columnName, "checkRange")) {
                    throw new ImportRecipientsToolongValueException(value);
                }
            }
            if (AgnUtils.isOracleDB()) {
                ps.setString(index, value);
            } else if (AgnUtils.isMySQLDB()) {
                if (column.isNullable() && value.isEmpty()) {
                    ps.setNull(index, Types.VARCHAR);
                } else {
                    ps.setString(index, value);
                }
            }

        }
    } else if (column.getType() == CSVColumnState.TYPE_NUMERIC) {
        if (StringUtils.isEmpty(value) || value == null) {
            ps.setNull(index, Types.NUMERIC);
        } else {
            ps.setDouble(index, Double.valueOf(value));
        }
    } else if (column.getType() == CSVColumnState.TYPE_DATE) {
        if (StringUtils.isEmpty(value) || value == null) {
            ps.setNull(index, Types.DATE);
        } else {
            Date date = ImportUtils.getDateAsString(value, importProfile.getDateFormat());

            ps.setTimestamp(index, new Timestamp(date.getTime()));
        }
    }
}

From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java

/**
 * Set the given value as a parameter to the statement.
 */// ww w  .ja v a 2s.c  o  m
public void setDate(PreparedStatement stmnt, int idx, Date val, Column col) throws SQLException {
    if (col != null && col.getType() == Types.DATE)
        setDate(stmnt, idx, new java.sql.Date(val.getTime()), null, col);
    else if (col != null && col.getType() == Types.TIME)
        setTime(stmnt, idx, new Time(val.getTime()), null, col);
    else if (val instanceof Timestamp)
        setTimestamp(stmnt, idx, (Timestamp) val, null, col);
    else
        setTimestamp(stmnt, idx, new Timestamp(val.getTime()), null, col);
}

From source file:org.apache.hadoop.hive.jdbc.TestJdbcDriver.java

public void testResultSetMetaData() throws SQLException {
    Statement stmt = con.createStatement();

    ResultSet res = stmt.executeQuery("select c1, c2, c3, c4, c5 as a, c6, c7, c8, c9, c10, c11, c12, "
            + "c1*2, sentences(null, null, null) as b, c17, c18, c20 from " + dataTypeTableName + " limit 1");
    ResultSetMetaData meta = res.getMetaData();

    ResultSet colRS = con.getMetaData().getColumns(null, null, dataTypeTableName.toLowerCase(), null);

    assertEquals(17, meta.getColumnCount());

    assertTrue(colRS.next());/*  www.  j a  v  a2  s.com*/

    assertEquals("c1", meta.getColumnName(1));
    assertEquals(Types.INTEGER, meta.getColumnType(1));
    assertEquals("int", meta.getColumnTypeName(1));
    assertEquals(11, meta.getColumnDisplaySize(1));
    assertEquals(10, meta.getPrecision(1));
    assertEquals(0, meta.getScale(1));

    assertEquals("c1", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.INTEGER, colRS.getInt("DATA_TYPE"));
    assertEquals("int", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(1), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(1), colRS.getInt("DECIMAL_DIGITS"));

    assertTrue(colRS.next());

    assertEquals("c2", meta.getColumnName(2));
    assertEquals("boolean", meta.getColumnTypeName(2));
    assertEquals(Types.BOOLEAN, meta.getColumnType(2));
    assertEquals(1, meta.getColumnDisplaySize(2));
    assertEquals(1, meta.getPrecision(2));
    assertEquals(0, meta.getScale(2));

    assertEquals("c2", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.BOOLEAN, colRS.getInt("DATA_TYPE"));
    assertEquals("boolean", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(2), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(2), colRS.getInt("DECIMAL_DIGITS"));

    assertTrue(colRS.next());

    assertEquals("c3", meta.getColumnName(3));
    assertEquals(Types.DOUBLE, meta.getColumnType(3));
    assertEquals("double", meta.getColumnTypeName(3));
    assertEquals(25, meta.getColumnDisplaySize(3));
    assertEquals(15, meta.getPrecision(3));
    assertEquals(15, meta.getScale(3));

    assertEquals("c3", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.DOUBLE, colRS.getInt("DATA_TYPE"));
    assertEquals("double", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(3), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(3), colRS.getInt("DECIMAL_DIGITS"));

    assertTrue(colRS.next());

    assertEquals("c4", meta.getColumnName(4));
    assertEquals(Types.VARCHAR, meta.getColumnType(4));
    assertEquals("string", meta.getColumnTypeName(4));
    assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(4));
    assertEquals(Integer.MAX_VALUE, meta.getPrecision(4));
    assertEquals(0, meta.getScale(4));

    assertEquals("c4", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.VARCHAR, colRS.getInt("DATA_TYPE"));
    assertEquals("string", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(4), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(4), colRS.getInt("DECIMAL_DIGITS"));

    assertTrue(colRS.next());

    assertEquals("a", meta.getColumnName(5));
    assertEquals(Types.VARCHAR, meta.getColumnType(5));
    assertEquals("string", meta.getColumnTypeName(5));
    assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(5));
    assertEquals(Integer.MAX_VALUE, meta.getPrecision(5));
    assertEquals(0, meta.getScale(5));

    assertEquals("c5", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.VARCHAR, colRS.getInt("DATA_TYPE"));
    assertEquals("array<int>", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(5), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(5), colRS.getInt("DECIMAL_DIGITS"));

    assertTrue(colRS.next());

    assertEquals("c6", meta.getColumnName(6));
    assertEquals(Types.VARCHAR, meta.getColumnType(6));
    assertEquals("string", meta.getColumnTypeName(6));
    assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(6));
    assertEquals(Integer.MAX_VALUE, meta.getPrecision(6));
    assertEquals(0, meta.getScale(6));

    assertEquals("c6", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.VARCHAR, colRS.getInt("DATA_TYPE"));
    assertEquals("map<int,string>", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(6), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(6), colRS.getInt("DECIMAL_DIGITS"));

    assertTrue(colRS.next());

    assertEquals("c7", meta.getColumnName(7));
    assertEquals(Types.VARCHAR, meta.getColumnType(7));
    assertEquals("string", meta.getColumnTypeName(7));
    assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(7));
    assertEquals(Integer.MAX_VALUE, meta.getPrecision(7));
    assertEquals(0, meta.getScale(7));

    assertEquals("c7", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.VARCHAR, colRS.getInt("DATA_TYPE"));
    assertEquals("map<string,string>", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(7), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(7), colRS.getInt("DECIMAL_DIGITS"));

    assertTrue(colRS.next());

    assertEquals("c8", meta.getColumnName(8));
    assertEquals(Types.VARCHAR, meta.getColumnType(8));
    assertEquals("string", meta.getColumnTypeName(8));
    assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(8));
    assertEquals(Integer.MAX_VALUE, meta.getPrecision(8));
    assertEquals(0, meta.getScale(8));

    assertEquals("c8", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.VARCHAR, colRS.getInt("DATA_TYPE"));
    assertEquals("struct<r:string,s:int,t:double>", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(8), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(8), colRS.getInt("DECIMAL_DIGITS"));

    assertTrue(colRS.next());

    assertEquals("c9", meta.getColumnName(9));
    assertEquals(Types.TINYINT, meta.getColumnType(9));
    assertEquals("tinyint", meta.getColumnTypeName(9));
    assertEquals(4, meta.getColumnDisplaySize(9));
    assertEquals(3, meta.getPrecision(9));
    assertEquals(0, meta.getScale(9));

    assertEquals("c9", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.TINYINT, colRS.getInt("DATA_TYPE"));
    assertEquals("tinyint", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(9), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(9), colRS.getInt("DECIMAL_DIGITS"));

    assertTrue(colRS.next());

    assertEquals("c10", meta.getColumnName(10));
    assertEquals(Types.SMALLINT, meta.getColumnType(10));
    assertEquals("smallint", meta.getColumnTypeName(10));
    assertEquals(6, meta.getColumnDisplaySize(10));
    assertEquals(5, meta.getPrecision(10));
    assertEquals(0, meta.getScale(10));

    assertEquals("c10", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.SMALLINT, colRS.getInt("DATA_TYPE"));
    assertEquals("smallint", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(10), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(10), colRS.getInt("DECIMAL_DIGITS"));

    assertTrue(colRS.next());

    assertEquals("c11", meta.getColumnName(11));
    assertEquals(Types.FLOAT, meta.getColumnType(11));
    assertEquals("float", meta.getColumnTypeName(11));
    assertEquals(24, meta.getColumnDisplaySize(11));
    assertEquals(7, meta.getPrecision(11));
    assertEquals(7, meta.getScale(11));

    assertEquals("c11", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.FLOAT, colRS.getInt("DATA_TYPE"));
    assertEquals("float", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(11), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(11), colRS.getInt("DECIMAL_DIGITS"));

    assertTrue(colRS.next());

    assertEquals("c12", meta.getColumnName(12));
    assertEquals(Types.BIGINT, meta.getColumnType(12));
    assertEquals("bigint", meta.getColumnTypeName(12));
    assertEquals(20, meta.getColumnDisplaySize(12));
    assertEquals(19, meta.getPrecision(12));
    assertEquals(0, meta.getScale(12));

    assertEquals("c12", colRS.getString("COLUMN_NAME"));
    assertEquals(Types.BIGINT, colRS.getInt("DATA_TYPE"));
    assertEquals("bigint", colRS.getString("TYPE_NAME").toLowerCase());
    assertEquals(meta.getPrecision(12), colRS.getInt("COLUMN_SIZE"));
    assertEquals(meta.getScale(12), colRS.getInt("DECIMAL_DIGITS"));

    assertEquals("_c12", meta.getColumnName(13));
    assertEquals(Types.INTEGER, meta.getColumnType(13));
    assertEquals("int", meta.getColumnTypeName(13));
    assertEquals(11, meta.getColumnDisplaySize(13));
    assertEquals(10, meta.getPrecision(13));
    assertEquals(0, meta.getScale(13));

    assertEquals("b", meta.getColumnName(14));
    assertEquals(Types.VARCHAR, meta.getColumnType(14));
    assertEquals("string", meta.getColumnTypeName(14));
    assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(14));
    assertEquals(Integer.MAX_VALUE, meta.getPrecision(14));
    assertEquals(0, meta.getScale(14));

    assertEquals("c17", meta.getColumnName(15));
    assertEquals(Types.TIMESTAMP, meta.getColumnType(15));
    assertEquals("timestamp", meta.getColumnTypeName(15));
    assertEquals(29, meta.getColumnDisplaySize(15));
    assertEquals(29, meta.getPrecision(15));
    assertEquals(9, meta.getScale(15));

    assertEquals("c18", meta.getColumnName(16));
    assertEquals(Types.DECIMAL, meta.getColumnType(16));
    assertEquals("decimal", meta.getColumnTypeName(16));
    assertEquals(Integer.MAX_VALUE, meta.getColumnDisplaySize(16));
    assertEquals(Integer.MAX_VALUE, meta.getPrecision(16));
    assertEquals(Integer.MAX_VALUE, meta.getScale(16));

    assertEquals("c20", meta.getColumnName(17));
    assertEquals(Types.DATE, meta.getColumnType(17));
    assertEquals("date", meta.getColumnTypeName(17));
    assertEquals(10, meta.getColumnDisplaySize(17));
    assertEquals(10, meta.getPrecision(17));
    assertEquals(0, meta.getScale(17));

    for (int i = 1; i <= meta.getColumnCount(); i++) {
        assertFalse(meta.isAutoIncrement(i));
        assertFalse(meta.isCurrency(i));
        assertEquals(ResultSetMetaData.columnNullable, meta.isNullable(i));
    }
}

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;/*from w w w  .  j a  va2 s  .  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;
}