Example usage for java.sql Types DOUBLE

List of usage examples for java.sql Types DOUBLE

Introduction

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

Prototype

int DOUBLE

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

Click Source Link

Document

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

Usage

From source file:org.apache.kylin.jdbc.KylinClient.java

public static Object wrapObject(String value, int sqlType) {
    if (null == value) {
        return null;
    }/*from  w ww . j  a va  2 s . c  om*/

    switch (sqlType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return value;
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimal(value);
    case Types.BIT:
        return Boolean.parseBoolean(value);
    case Types.TINYINT:
        return Byte.valueOf(value);
    case Types.SMALLINT:
        return Short.valueOf(value);
    case Types.INTEGER:
        return Integer.parseInt(value);
    case Types.BIGINT:
        return Long.parseLong(value);
    case Types.FLOAT:
        return Float.parseFloat(value);
    case Types.REAL:
    case Types.DOUBLE:
        return Double.parseDouble(value);
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return value.getBytes();
    case Types.DATE:
        return Date.valueOf(value);
    case Types.TIME:
        return Time.valueOf(value);
    case Types.TIMESTAMP:
        return Timestamp.valueOf(value);
    default:
        //do nothing
        break;

    }

    return value;
}

From source file:org.apache.tajo.storage.jdbc.JdbcMetadataProviderBase.java

private TypeDesc convertDataType(ResultSet res) throws SQLException {
    final int typeId = res.getInt("DATA_TYPE");

    switch (typeId) {
    case Types.BOOLEAN:
        return new TypeDesc(newSimpleDataType(Type.BOOLEAN));

    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
        return new TypeDesc(newSimpleDataType(Type.INT4));

    case Types.DISTINCT: // sequence for postgresql
    case Types.BIGINT:
        return new TypeDesc(newSimpleDataType(Type.INT8));

    case Types.FLOAT:
        return new TypeDesc(newSimpleDataType(Type.FLOAT4));

    case Types.NUMERIC:
    case Types.DECIMAL:
    case Types.DOUBLE:
        return new TypeDesc(newSimpleDataType(Type.FLOAT8));

    case Types.DATE:
        return new TypeDesc(newSimpleDataType(Type.DATE));

    case Types.TIME:
        return new TypeDesc(newSimpleDataType(Type.TIME));

    case Types.TIMESTAMP:
        return new TypeDesc(newSimpleDataType(Type.TIMESTAMP));

    case Types.CHAR:
    case Types.NCHAR:
    case Types.VARCHAR:
    case Types.NVARCHAR:
    case Types.CLOB:
    case Types.NCLOB:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
        return new TypeDesc(newSimpleDataType(Type.TEXT));

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB:
        return new TypeDesc(newSimpleDataType(Type.BLOB));

    default://from   w w w  . j a  v a 2 s .c  o m
        throw SQLExceptionUtil.toSQLException(new UnsupportedDataTypeException(typeId + ""));
    }
}

From source file:madgik.exareme.master.queryProcessor.analyzer.stat.Stat.java

private int computeColumnSize(String columnName, int columnType, String table_sample) throws Exception {
    int columnSize = 0;
    if (columnType == Types.INTEGER || columnType == Types.REAL || columnType == Types.DOUBLE
            || columnType == Types.DECIMAL || columnType == Types.FLOAT || columnType == Types.NUMERIC) {
        columnSize = NUM_SIZE;/*from  ww w  . j av a  2 s.  c o  m*/
    } else if (columnType == Types.VARCHAR) {
        String query0 = "select max(length(`" + columnName + "`)) as length from (select `" + columnName
                + "` from `" + table_sample + "`)" + " where `" + columnName + "` is not null limit "
                + MAX_STRING_SAMPLE;

        Statement stmt0 = con.createStatement();
        ResultSet rs0 = stmt0.executeQuery(query0);

        while (rs0.next()) {
            columnSize = rs0.getInt("length");
        }
        rs0.close();
        stmt0.close();

    } else if (columnType == Types.BLOB)
        columnSize = BLOB_SIZE;

    return columnSize;
}

From source file:co.nubetech.apache.hadoop.DataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query
 *         into InputSplits.//from  w  ww .  j  av a  2  s.c o  m
 */
protected DBSplitter getSplitter(int sqlDataType) {
    switch (sqlDataType) {
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimalSplitter();

    case Types.BIT:
    case Types.BOOLEAN:
        return new BooleanSplitter();

    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.BIGINT:
        return new IntegerSplitter();

    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
        return new FloatSplitter();

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return new TextSplitter();

    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return new DateSplitter();

    default:
        // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB,
        // BLOB, ARRAY
        // STRUCT, REF, DATALINK, and JAVA_OBJECT.
        return null;
    }
}

From source file:org.apache.tika.parser.jdbc.JDBCTableReader.java

private void handleCell(ResultSetMetaData rsmd, int i, ContentHandler handler, ParseContext context)
        throws SQLException, IOException, SAXException {
    switch (rsmd.getColumnType(i)) {
    case Types.BLOB:
        handleBlob(tableName, rsmd.getColumnName(i), rows, results, i, handler, context);
        break;//from  w  w w. j av  a  2 s .  c o  m
    case Types.CLOB:
        handleClob(tableName, rsmd.getColumnName(i), rows, results, i, handler, context);
        break;
    case Types.BOOLEAN:
        handleBoolean(results, i, handler);
        break;
    case Types.DATE:
        handleDate(results, i, handler);
        break;
    case Types.TIMESTAMP:
        handleTimeStamp(results, i, handler);
        break;
    case Types.INTEGER:
        handleInteger(results, i, handler);
        break;
    case Types.FLOAT:
        //this is necessary to handle rounding issues in presentation
        //Should we just use getString(i)?
        float f = results.getFloat(i);
        if (!results.wasNull()) {
            addAllCharacters(Float.toString(f), handler);
        }
        break;
    case Types.DOUBLE:
        double d = results.getDouble(i);
        if (!results.wasNull()) {
            addAllCharacters(Double.toString(d), handler);
        }
        break;
    default:
        String s = results.getString(i);
        if (!results.wasNull()) {
            addAllCharacters(s, handler);
        }
        break;
    }
}

From source file:co.nubetech.hiho.mapreduce.lib.db.apache.DataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query into InputSplits.
 *///  w  ww. j  a  va 2s  .  c o  m
protected DBSplitter getSplitter(int sqlDataType) {
    switch (sqlDataType) {
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimalSplitter();

    case Types.BIT:
    case Types.BOOLEAN:
        return new BooleanSplitter();

    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.BIGINT:
        return new IntegerSplitter();

    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
        return new FloatSplitter();

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return new TextSplitter();

    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return new DateSplitter();

    default:
        // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, BLOB, ARRAY
        // STRUCT, REF, DATALINK, and JAVA_OBJECT.
        return null;
    }
}

From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type.spec) {
    case STRING://from w  w  w .j  av  a 2  s  . com
        if (type.isUnconstrained()) {
            return jdbcInfo("varchar", Types.VARCHAR);
        } else if (type.isClob()) {
            return jdbcInfo("text", Types.CLOB);
        } else {
            return jdbcInfo("varchar(%d)", type.length, Types.VARCHAR);
        }
    case BOOLEAN:
        return jdbcInfo("bool", Types.BIT);
    case LONG:
        return jdbcInfo("int8", Types.BIGINT);
    case DOUBLE:
        return jdbcInfo("float8", Types.DOUBLE);
    case TIMESTAMP:
        return jdbcInfo("timestamp", Types.TIMESTAMP);
    case BLOBID:
        return jdbcInfo("varchar(40)", Types.VARCHAR);
    // -----
    case NODEID:
    case NODEIDFK:
    case NODEIDFKNP:
    case NODEIDFKMUL:
    case NODEIDFKNULL:
    case NODEIDPK:
    case NODEVAL:
        return jdbcInfo("varchar(36)", Types.VARCHAR);
    case NODEARRAY:
        return jdbcInfo("varchar(36)[]", Types.ARRAY);
    case SYSNAME:
        return jdbcInfo("varchar(250)", Types.VARCHAR);
    case SYSNAMEARRAY:
        return jdbcInfo("varchar(250)[]", Types.ARRAY);
    case TINYINT:
        return jdbcInfo("int2", Types.SMALLINT);
    case INTEGER:
        return jdbcInfo("int4", Types.INTEGER);
    case FTINDEXED:
        return jdbcInfo("tsvector", Types.OTHER);
    case FTSTORED:
        return jdbcInfo("tsvector", Types.OTHER);
    case CLUSTERNODE:
        return jdbcInfo("int4", Types.INTEGER);
    case CLUSTERFRAGS:
        return jdbcInfo("varchar[]", Types.ARRAY);
    }
    throw new AssertionError(type);
}

From source file:org.apache.ddlutils.platform.mssql.MSSqlBuilder.java

/**
 * {@inheritDoc}/* w ww .j  a  v  a  2  s  .  c o  m*/
 */
protected String getValueAsString(Column column, Object value) {
    if (value == null) {
        return "NULL";
    }

    StringBuffer result = new StringBuffer();

    switch (column.getTypeCode()) {
    case Types.REAL:
    case Types.NUMERIC:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.DECIMAL:
        // SQL Server does not want quotes around the value
        if (!(value instanceof String) && (getValueNumberFormat() != null)) {
            result.append(getValueNumberFormat().format(value));
        } else {
            result.append(value.toString());
        }
        break;
    case Types.DATE:
        result.append("CAST(");
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(value instanceof String ? (String) value : getValueDateFormat().format(value));
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(" AS datetime)");
        break;
    case Types.TIME:
        result.append("CAST(");
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(value instanceof String ? (String) value : getValueTimeFormat().format(value));
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(" AS datetime)");
        break;
    case Types.TIMESTAMP:
        result.append("CAST(");
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(value.toString());
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(" AS datetime)");
        break;
    }
    return super.getValueAsString(column, value);
}

From source file:org.brucalipto.sqlutil.DB2SQLManager.java

/**
 * Method useful for using STORED PROCEDURE
 * @param spib The {@link SPInputBean} bean containing data to execute the stored procedure
 * @return The {@link SPOutputBean} containing returned values
 *//*www .ja  va2s.  co  m*/
public SPOutputBean executeSP(final SPInputBean spib) throws SQLException {
    Connection conn = null;
    CallableStatement call = null;
    ResultSet resultSet = null;
    final String procedureName = spib.spName;

    SPParameter[] inputParameters = spib.inputParams;
    int[] outputParameters = spib.outputParams;

    final int inputParametersSize = inputParameters.length;
    final int outputParametersSize = outputParameters.length;

    final StringBuffer spName = new StringBuffer("call ").append(procedureName).append('(');
    int totalParameters = inputParametersSize + outputParametersSize;
    for (int i = 0; i < totalParameters; i++) {
        if (i != totalParameters - 1) {
            spName.append("?,");
        } else {
            spName.append('?');
        }
    }
    spName.append(")");

    try {
        if (this.dataSource != null) {
            conn = this.dataSource.getConnection();
        } else {
            conn = this.connection;
        }
        call = conn.prepareCall(spName.toString());
        for (int i = 0; i < inputParametersSize; i++) {
            final SPParameter inputParam = inputParameters[i];
            final int sqlType = inputParam.sqlType;
            final Object inputParamValue = inputParam.value;
            log.debug((i + 1) + ") Setting input value: " + inputParam);
            if (inputParamValue == null) {
                call.setNull(i + 1, sqlType);
                continue;
            }
            switch (sqlType) {
            case Types.VARCHAR:
                call.setString(i + 1, (String) inputParamValue);
                break;
            case Types.INTEGER:
                if (inputParamValue instanceof Integer) {
                    call.setInt(i + 1, ((Integer) inputParamValue).intValue());
                } else if (inputParamValue instanceof Long) {
                    call.setLong(i + 1, ((Long) inputParamValue).longValue());
                }
                break;
            case Types.DATE:
                call.setDate(i + 1, (Date) inputParamValue);
                break;
            case Types.BOOLEAN:
                call.setBoolean(i + 1, ((Boolean) inputParamValue).booleanValue());
                break;
            case Types.CHAR:
                call.setString(i + 1, ((Character) inputParamValue).toString());
                break;
            case Types.DOUBLE:
                call.setDouble(i + 1, ((Double) inputParamValue).doubleValue());
                break;
            case Types.FLOAT:
                call.setFloat(i + 1, ((Float) inputParamValue).floatValue());
                break;
            case Types.TIMESTAMP:
                call.setTimestamp(i + 1, (Timestamp) inputParamValue);
                break;
            default:
                call.setObject(i + 1, inputParamValue);
                break;
            }
        }

        for (int i = 0; i < outputParametersSize; i++) {
            int sqlType = outputParameters[i];
            log.debug((i + 1) + ") Registering output type 'Types."
                    + SQLUtilTypes.SQL_TYPES.get(Integer.valueOf("" + sqlType)) + "'");
            call.registerOutParameter(inputParametersSize + i + 1, sqlType);
        }

        log.debug("Going to call: '" + procedureName + "'");
        long elapsedTime = System.currentTimeMillis();
        boolean hasResultSet = call.execute();
        log.debug("SP '" + procedureName + "' executed in " + (System.currentTimeMillis() - elapsedTime)
                + "millis");
        if (hasResultSet) {
            log.debug("This SP is going to return also a resultSet");
        }

        final SPOutputBean output = new SPOutputBean();
        for (int i = 0; i < outputParametersSize; i++) {
            int sqlType = outputParameters[i];
            log.debug((i + 1) + ") Getting output type 'Types."
                    + SQLUtilTypes.SQL_TYPES.get(Integer.valueOf("" + sqlType)) + "'");
            final Object spResult = call.getObject(inputParametersSize + i + 1);
            SPParameter outParam = new SPParameter(sqlType, spResult);
            output.addResult(outParam);
        }
        if (hasResultSet) {
            RowSetDynaClass rowSetDynaClass = new RowSetDynaClass(call.getResultSet(), false);
            if (log.isDebugEnabled()) {
                log.debug("Going to return a RowSetDynaClass with following properties:");
                DynaProperty[] properties = rowSetDynaClass.getDynaProperties();
                for (int i = 0; i < properties.length; i++) {
                    log.debug("Name: '" + properties[i].getName() + "'; Type: '"
                            + properties[i].getType().getName() + "'");
                }
            }
            SPParameter outParam = new SPParameter(Types.JAVA_OBJECT, rowSetDynaClass);
            output.addResult(outParam);
        }
        return output;
    } finally {
        closeResources(resultSet, call, conn);
    }
}

From source file:org.brucalipto.sqlutil.OracleSQLManager.java

/**
* Method useful for using STORED PROCEDURE
* @param spib The {@link SPInputBean} bean containing data to execute the stored procedure
* @return The {@link SPOutputBean} containing returned values
*//*from  w  ww  . j a  v  a  2 s  .  com*/
public SPOutputBean executeSP(final SPInputBean spib) throws SQLException {
    Connection conn = null;
    CallableStatement call = null;
    ResultSet resultSet = null;
    final String procedureName = spib.spName;

    SPParameter[] inputParameters = spib.inputParams;
    int[] outputParameters = spib.outputParams;

    final int inputParametersSize = inputParameters.length;
    final int outputParametersSize = outputParameters.length;

    final StringBuffer spName = new StringBuffer("{ call ").append(procedureName).append('(');
    int totalParameters = inputParametersSize + outputParametersSize;
    for (int i = 0; i < totalParameters; i++) {
        if (i != totalParameters - 1) {
            spName.append("?,");
        } else {
            spName.append('?');
        }
    }
    spName.append(") }");
    log.debug("Going to call: '" + spName + "'");

    try {
        conn = this.dataSource.getConnection();
        call = conn.prepareCall(spName.toString());
        for (int i = 0; i < inputParametersSize; i++) {
            final SPParameter inputParam = inputParameters[i];
            final int sqlType = inputParam.sqlType;
            final Object inputParamValue = inputParam.value;
            log.debug((i + 1) + ") Setting input value 'Types."
                    + SQLUtilTypes.SQL_TYPES.get(Integer.valueOf("" + sqlType)) + "'-'" + inputParamValue
                    + "'");
            if (inputParamValue == null) {
                call.setNull(i + 1, sqlType);
                continue;
            }
            switch (sqlType) {
            case Types.VARCHAR:
                call.setString(i + 1, (String) inputParamValue);
                break;
            case Types.INTEGER:
                if (inputParamValue instanceof Integer) {
                    call.setInt(i + 1, ((Integer) inputParamValue).intValue());
                } else if (inputParamValue instanceof Long) {
                    call.setLong(i + 1, ((Long) inputParamValue).longValue());
                }
                break;
            case Types.DATE:
                call.setDate(i + 1, (Date) inputParamValue);
                break;
            case Types.BOOLEAN:
                call.setBoolean(i + 1, ((Boolean) inputParamValue).booleanValue());
                break;
            case Types.CHAR:
                call.setString(i + 1, ((Character) inputParamValue).toString());
                break;
            case Types.DOUBLE:
                call.setDouble(i + 1, ((Double) inputParamValue).doubleValue());
                break;
            case Types.FLOAT:
                call.setFloat(i + 1, ((Float) inputParamValue).floatValue());
                break;
            case Types.TIMESTAMP:
                call.setTimestamp(i + 1, (Timestamp) inputParamValue);
                break;
            default:
                call.setObject(i + 1, inputParamValue);
                break;
            }
        }

        for (int i = 0; i < outputParametersSize; i++) {
            int sqlType = outputParameters[i];
            log.debug((i + 1) + ") Registering output type 'Types."
                    + SQLUtilTypes.SQL_TYPES.get(Integer.valueOf("" + sqlType)) + "'");
            call.registerOutParameter(inputParametersSize + i + 1, sqlType);
        }

        call.execute();

        final SPOutputBean output = new SPOutputBean();
        for (int i = 0; i < outputParametersSize; i++) {
            int sqlType = outputParameters[i];
            log.debug((i + 1) + ") Getting output type 'Types."
                    + SQLUtilTypes.SQL_TYPES.get(Integer.valueOf("" + sqlType)) + "'");
            final Object spResult = call.getObject(inputParametersSize + i + 1);
            SPParameter outParam = null;
            if (sqlType == SQLUtilTypes.CURSOR) {
                resultSet = (ResultSet) spResult;
                RowSetDynaClass rowSetDynaClass = new RowSetDynaClass(resultSet, false);
                if (log.isDebugEnabled()) {
                    log.debug("Going to return a RowSetDynaClass with following properties:");
                    DynaProperty[] properties = rowSetDynaClass.getDynaProperties();
                    for (int j = 0; j < properties.length; j++) {
                        log.debug("Name: '" + properties[j].getName() + "'; Type: '"
                                + properties[j].getType().getName() + "'");
                    }
                }
                outParam = new SPParameter(sqlType, rowSetDynaClass);
            } else {
                outParam = new SPParameter(sqlType, spResult);
            }
            output.addResult(outParam);
        }

        return output;
    } catch (SQLException sqle) {
        log.error("Caught SQLException", sqle);
    } finally {
        closeResources(resultSet, call, conn);
    }

    return null;
}