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:oscar.util.SqlUtils.java

private static Object getNewType(ResultSet rs, int colNum) {
    int type = 0;
    try {//from w  w  w. jav a  2s. c o m
        type = rs.getMetaData().getColumnType(colNum);
        switch (type) {
        case Types.LONGVARCHAR:
        case Types.CHAR:
        case Types.VARCHAR:
            return oscar.Misc.getString(rs, colNum);
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            return new Integer(rs.getInt(colNum));
        case Types.BIGINT:
            return new Long(rs.getLong(colNum));
        case Types.FLOAT:
        case Types.DECIMAL:
        case Types.REAL:
        case Types.DOUBLE:
        case Types.NUMERIC:
            return new Double(rs.getDouble(colNum));
        // case Types.B
        case Types.BIT:
            return new Boolean(rs.getBoolean(colNum));
        case Types.TIMESTAMP:
        case Types.DATE:
        case Types.TIME:
            return rs.getDate(colNum);
        default:
            return rs.getObject(colNum);
        }
    } catch (Exception e) {
        MiscUtils.getLogger().error("Error", e);
    }
    return null;
}

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 v a 2s . com*/

        }
        array.put(obj);

    }
    return array.toString();
}

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

/**
 * Method useful for SQL SELECT/*from  w  ww  . j a  v a 2  s  .c om*/
 * @param preparedStatement The prepared statement to execute
 * @param params List of {@link SQLParameter} to use to complete the prepared statement
 * @param outputSQLType A java.sql.Types type of return value
 * @return The {@link SPParameter} containing the returned value
 */
public SQLParameter simpleSelect(final String preparedStatement, SQLParameter[] params,
        final int outputSQLType) {
    final SQLParameter[] parameters;
    if (params == null) {
        parameters = new SQLParameter[0];
        log.debug("Going to execute a query without parameters.");
    } else {
        parameters = (SQLParameter[]) params.clone();
    }
    Connection dbConn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        if (this.dataSource != null) {
            dbConn = this.dataSource.getConnection();
        } else {
            dbConn = this.connection;
        }
        pstmt = dbConn.prepareStatement(preparedStatement);
        for (int i = 0; i < parameters.length; i++) {
            final SQLParameter param = parameters[i];
            log.debug((i + 1) + ") Going to add parameter " + param);
            final int sqlType = param.getSqlType();
            final Object paramValue = param.getValue();
            if (paramValue == null) {
                pstmt.setNull(i + 1, sqlType);
                continue;
            }
            switch (sqlType) {
            case Types.VARCHAR:
                pstmt.setString(i + 1, (String) paramValue);
                break;
            case Types.INTEGER:
                if (paramValue instanceof Integer) {
                    pstmt.setInt(i + 1, ((Integer) paramValue).intValue());
                } else if (paramValue instanceof Long) {
                    pstmt.setLong(i + 1, ((Long) paramValue).longValue());
                }
                break;
            case Types.DATE:
                pstmt.setDate(i + 1, (Date) paramValue);
                break;
            case Types.BOOLEAN:
                pstmt.setBoolean(i + 1, ((Boolean) paramValue).booleanValue());
                break;
            case Types.CHAR:
                pstmt.setString(i + 1, ((Character) paramValue).toString());
                break;
            case Types.DOUBLE:
                pstmt.setDouble(i + 1, ((Double) paramValue).doubleValue());
                break;
            case Types.FLOAT:
                pstmt.setFloat(i + 1, ((Float) paramValue).floatValue());
                break;
            case Types.TIMESTAMP:
                pstmt.setTimestamp(i + 1, (Timestamp) paramValue);
                break;
            default:
                pstmt.setObject(i + 1, paramValue);
                break;
            }
        }

        rs = pstmt.executeQuery();
        log.debug("Prepared statement '" + preparedStatement + "' succesfully executed!");
        while (rs.next()) {
            return new SQLParameter(outputSQLType, (Serializable) rs.getObject(1));
        }
        log.info("Prepared statement '" + preparedStatement + "' returned '0' rows");
    } catch (SQLException e) {
        log.error("Error executing prepared statement '" + preparedStatement + "'", e);
    } catch (Exception e) {
        log.error("Error executing prepared statement '" + preparedStatement + "'", e);
    } finally {
        closeResources(rs, pstmt, dbConn);
    }

    return new SQLParameter(outputSQLType, null);
}

From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectSQLServer.java

@Override
@SuppressWarnings("boxing")
public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException {
    switch (column.getJdbcType()) {
    case Types.VARCHAR:
    case Types.CLOB:
        return getFromResultSetString(rs, index, column);
    case Types.BIT:
        return rs.getBoolean(index);
    case Types.TINYINT:
    case Types.INTEGER:
    case Types.BIGINT:
        return rs.getLong(index);
    case Types.DOUBLE:
        return rs.getDouble(index);
    case Types.TIMESTAMP:
        return getFromResultSetTimestamp(rs, index, column);
    }//w ww.  ja  v a  2s. com
    throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
}

From source file:org.athenasource.framework.unidbi.Datatypes.java

/**
 * Returns the corresponding type as defined in {@link java.sql.Types} of the given UniDB datatype.
 * @param unidbType the UniDB datatype.//from  w w  w. j ava 2  s  . c  om
 * @return the corresponding type as defined in {@link java.sql.Types} of the given UniDB datatype.
 */
public static int getSQLType(int unidbType) {
    switch (unidbType) {
    case BOOLEAN:
        return Types.TINYINT;
    case TINYINT:
        return Types.TINYINT;
    case SMALLINT:
        return Types.SMALLINT;
    case INTEGER:
        return Types.INTEGER;
    case BIGINT:
        return Types.BIGINT;
    case DECIMAL:
        return Types.DECIMAL;
    case REAL:
        return Types.REAL;
    case DOUBLE:
        return Types.DOUBLE;
    case CHAR:
        return Types.CHAR;
    case NCHAR:
        return Types.NCHAR;
    case VARCHAR:
        return Types.VARCHAR;
    case NVARCHAR:
        return Types.NVARCHAR;
    case CLOB: // Clob/NClob can be represented as String without any problem. - Oct 16, 2008.
        // but returns this type should be ok.
        return Types.CLOB;
    case NCLOB:
        return Types.NCLOB;
    case BLOB:
        return Types.BLOB;
    case TIMESTAMP:
        return Types.TIMESTAMP;
    default:
        throw new IllegalArgumentException("[!NO SUCH UNIDB DATA TYPE: " + unidbType + "]");
    }
}

From source file:com.alibaba.otter.node.etl.common.db.utils.SqlUtils.java

/**
 * Check whether the given SQL type is numeric.
 *//*  ww  w  .  j a v a  2 s.c  o m*/
public static boolean isNumeric(int sqlType) {
    return (Types.BIT == sqlType) || (Types.BIGINT == sqlType) || (Types.DECIMAL == sqlType)
            || (Types.DOUBLE == sqlType) || (Types.FLOAT == sqlType) || (Types.INTEGER == sqlType)
            || (Types.NUMERIC == sqlType) || (Types.REAL == sqlType) || (Types.SMALLINT == sqlType)
            || (Types.TINYINT == sqlType);
}

From source file:org.latticesoft.util.resource.dao.Param.java

private void setValueToStatement(Object o, PreparedStatement pstmt) throws SQLException {
    if (log.isDebugEnabled()) {
        log.debug(this.sqlIndex + "=" + o);
    }/*w w w. j a va  2 s  .c  o m*/
    switch (this.sqlType) {
    case Types.VARCHAR:
    case Types.CHAR:
        String s = (String) o;
        pstmt.setString(this.sqlIndex, s);
        break;
    case Types.BOOLEAN:
        if (o != null && o instanceof Boolean) {
            boolean b = ((Boolean) o).booleanValue();
            pstmt.setBoolean(this.sqlIndex, b);
        }
        break;
    case Types.INTEGER:
        if (o != null && o instanceof Integer) {
            int i = ((Integer) o).intValue();
            pstmt.setInt(this.sqlIndex, i);
        }
        break;
    case Types.SMALLINT:
        if (o != null && o instanceof Short) {
            short ss = ((Short) o).shortValue();
            pstmt.setShort(this.sqlIndex, ss);
        }
        break;
    case Types.TINYINT:
        if (o != null && o instanceof Byte) {
            byte bb = ((Byte) o).byteValue();
            pstmt.setByte(this.sqlIndex, bb);
        }
        break;
    case Types.BIGINT:
        if (o != null && o instanceof Long) {
            long l = ((Long) o).longValue();
            pstmt.setLong(this.sqlIndex, l);
        }
        break;
    case Types.DOUBLE:
        if (o != null && o instanceof Double) {
            double dd = ((Double) o).doubleValue();
            pstmt.setDouble(this.sqlIndex, dd);
        }
        break;
    case Types.FLOAT:
        if (o != null && o instanceof Float) {
            float f = ((Float) o).floatValue();
            pstmt.setFloat(this.sqlIndex, f);
        }
        break;
    case Types.NUMERIC:
        if (o != null && o instanceof BigDecimal) {
            BigDecimal bd = (BigDecimal) o;
            pstmt.setBigDecimal(this.sqlIndex, bd);
        }
        break;
    case Types.TIMESTAMP:
        if (o != null && o instanceof Timestamp) {
            Timestamp ts = (Timestamp) o;
            pstmt.setTimestamp(this.sqlIndex, ts);
        }
        break;
    case Types.NULL:
        if (log.isDebugEnabled()) {
            log.debug(this.sqlIndex + " IS NULL");
        }
        pstmt.setNull(this.sqlIndex, Types.NULL);
        break;
    default:
        if (o != null) {
            pstmt.setObject(this.sqlIndex, o);
        }
    }
}

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

public static int FromTypeName(String SQLName) {
    if (SQLName.equals("ARRAY")) {
        return Types.ARRAY;
    }//from  w ww  .  ja v a 2s.  com
    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.jumpmind.db.model.Column.java

/**
 * Tries to parse the default value of the column and returns it as an
 * object of the corresponding java type. If the value could not be parsed,
 * then the original definition is returned.
 * /* w w  w  .  j a v a2  s .c  om*/
 * @return The parsed default value
 */
public Object getParsedDefaultValue() {
    if ((defaultValue != null) && (defaultValue.length() > 0)) {
        try {
            switch (mappedTypeCode) {
            case Types.TINYINT:
            case Types.SMALLINT:
                return new Short(defaultValue);
            case Types.INTEGER:
                try {
                    return new Integer(defaultValue);
                } catch (NumberFormatException e) {
                    return new Long(defaultValue);
                }
            case Types.BIGINT:
                return new Long(defaultValue);
            case Types.DECIMAL:
            case Types.NUMERIC:
                return new BigDecimal(defaultValue);
            case Types.REAL:
                return new Float(defaultValue);
            case Types.DOUBLE:
            case Types.FLOAT:
                return new Double(defaultValue);
            case Types.DATE:
                return Date.valueOf(defaultValue);
            case Types.TIME:
                return Time.valueOf(defaultValue);
            case Types.TIMESTAMP:
                return Timestamp.valueOf(defaultValue);
            case Types.BIT:
                return FormatUtils.toBoolean(defaultValue);
            default:
                if (PlatformUtils.supportsJava14JdbcTypes()
                        && (mappedTypeCode == PlatformUtils.determineBooleanTypeCode())) {
                    return FormatUtils.toBoolean(defaultValue);
                }
                break;
            }
        } catch (NumberFormatException ex) {
            return null;
        } catch (IllegalArgumentException ex) {
            return null;
        }
    }
    return defaultValue;
}

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

/**
 * Returns a string representation of the provided type.
 * //from  w  ww.  ja v  a2  s . 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*";
    }
}