Example usage for java.sql Types FLOAT

List of usage examples for java.sql Types FLOAT

Introduction

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

Prototype

int FLOAT

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

Click Source Link

Document

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

Usage

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   w  ww . ja  v  a  2s  .c o m*/
 *  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:oscar.util.SqlUtils.java

/**
 * this utility-method assigns a particular value to a place holder of a PreparedStatement. it tries to find the correct setXxx() value, accoring to the field-type information
 * represented by "fieldType". quality: this method is bloody alpha (as you migth see :=)
 *///ww w .  j  a v  a  2  s. com
public static void fillPreparedStatement(PreparedStatement ps, int col, Object val, int fieldType)
        throws SQLException {
    try {
        logger.info("fillPreparedStatement( ps, " + col + ", " + val + ", " + fieldType + ")...");
        Object value = null;
        // Check for hard-coded NULL
        if (!("$null$".equals(val))) {
            value = val;
        }
        if (value != null) {
            switch (fieldType) {
            case FieldTypes.INTEGER:
                ps.setInt(col, Integer.parseInt((String) value));
                break;
            case FieldTypes.NUMERIC:
                ps.setBigDecimal(col, createAppropriateNumeric(value));
                break;
            case FieldTypes.CHAR:
                ps.setString(col, (String) value);
                break;
            case FieldTypes.DATE:
                ps.setDate(col, createAppropriateDate(value));
                break; // #checkme
            case FieldTypes.TIMESTAMP:
                ps.setTimestamp(col, java.sql.Timestamp.valueOf((String) value));
                break;
            case FieldTypes.DOUBLE:
                ps.setDouble(col, Double.valueOf((String) value).doubleValue());
                break;
            case FieldTypes.FLOAT:
                ps.setFloat(col, Float.valueOf((String) value).floatValue());
                break;
            case FieldTypes.LONG:
                ps.setLong(col, Long.parseLong(String.valueOf(value)));
                break;
            case FieldTypes.BLOB:
                FileHolder fileHolder = (FileHolder) value;
                try {
                    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
                    ObjectOutputStream out = new ObjectOutputStream(byteOut);
                    out.writeObject(fileHolder);
                    out.flush();
                    byte[] buf = byteOut.toByteArray();
                    byteOut.close();
                    out.close();
                    ByteArrayInputStream bytein = new ByteArrayInputStream(buf);
                    int byteLength = buf.length;
                    ps.setBinaryStream(col, bytein, byteLength);
                    // store fileHolder as a whole (this way we don't lose file meta-info!)
                } catch (IOException ioe) {
                    MiscUtils.getLogger().error("Error", ioe);
                    logger.info(ioe.toString());
                    throw new SQLException("error storing BLOB in database - " + ioe.toString(), null, 2);
                }
                break;
            case FieldTypes.DISKBLOB:
                ps.setString(col, (String) value);
                break;
            default:
                ps.setObject(col, value); // #checkme
            }
        } else {
            switch (fieldType) {
            case FieldTypes.INTEGER:
                ps.setNull(col, java.sql.Types.INTEGER);
                break;
            case FieldTypes.NUMERIC:
                ps.setNull(col, java.sql.Types.NUMERIC);
                break;
            case FieldTypes.CHAR:
                ps.setNull(col, java.sql.Types.CHAR);
                break;
            case FieldTypes.DATE:
                ps.setNull(col, java.sql.Types.DATE);
                break;
            case FieldTypes.TIMESTAMP:
                ps.setNull(col, java.sql.Types.TIMESTAMP);
                break;
            case FieldTypes.DOUBLE:
                ps.setNull(col, java.sql.Types.DOUBLE);
                break;
            case FieldTypes.FLOAT:
                ps.setNull(col, java.sql.Types.FLOAT);
                break;
            case FieldTypes.BLOB:
                ps.setNull(col, java.sql.Types.BLOB);
            case FieldTypes.DISKBLOB:
                ps.setNull(col, java.sql.Types.CHAR);
            default:
                ps.setNull(col, java.sql.Types.OTHER);
            }
        }
    } catch (Exception e) {
        throw new SQLException("Field type seems to be incorrect - " + e.toString(), null, 1);
    }
}

From source file:org.jumpmind.db.sql.DmlStatement.java

protected int getTypeCode(Column column, boolean isDateOverrideToTimestamp) {
    int type = column.getMappedTypeCode();
    if (type == Types.DATE && isDateOverrideToTimestamp) {
        type = Types.TIMESTAMP;/*from  w w  w . ja va2  s  .co m*/
    } else if (type == Types.FLOAT || type == Types.DOUBLE || type == Types.REAL) {
        type = Types.DECIMAL;
    }
    return type;
}

From source file:CreateNewTable.java

private static Vector getDataTypes(Connection con) throws SQLException {
    String structName = null, distinctName = null, javaName = null;

    // create a vector of class DataType initialized with
    // the SQL code, the SQL type name, and two null entries
    // for the local type name and the creation parameter(s)

    Vector dataTypes = new Vector();
    dataTypes.add(new DataType(java.sql.Types.BIT, "BIT"));
    dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT"));
    dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT"));
    dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER"));
    dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT"));
    dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT"));
    dataTypes.add(new DataType(java.sql.Types.REAL, "REAL"));
    dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE"));
    dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC"));
    dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL"));
    dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR"));
    dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR"));
    dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR"));
    dataTypes.add(new DataType(java.sql.Types.DATE, "DATE"));
    dataTypes.add(new DataType(java.sql.Types.TIME, "TIME"));
    dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP"));
    dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY"));
    dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY"));
    dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY"));
    dataTypes.add(new DataType(java.sql.Types.NULL, "NULL"));
    dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER"));
    dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB"));
    dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB"));

    DatabaseMetaData dbmd = con.getMetaData();
    ResultSet rs = dbmd.getTypeInfo();
    while (rs.next()) {
        int codeNumber = rs.getInt("DATA_TYPE");
        String dbmsName = rs.getString("TYPE_NAME");
        String createParams = rs.getString("CREATE_PARAMS");

        if (codeNumber == Types.STRUCT && structName == null)
            structName = dbmsName;//from w w  w.ja v a  2s  . c  o m
        else if (codeNumber == Types.DISTINCT && distinctName == null)
            distinctName = dbmsName;
        else if (codeNumber == Types.JAVA_OBJECT && javaName == null)
            javaName = dbmsName;
        else {
            for (int i = 0; i < dataTypes.size(); i++) {
                // find entry that matches the SQL code, 
                // and if local type and params are not already set,
                // set them
                DataType type = (DataType) dataTypes.get(i);
                if (type.getCode() == codeNumber) {
                    type.setLocalTypeAndParams(dbmsName, createParams);
                }
            }
        }
    }

    int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT };
    rs = dbmd.getUDTs(null, "%", "%", types);
    while (rs.next()) {
        String typeName = null;
        DataType dataType = null;

        if (dbmd.isCatalogAtStart())
            typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3);
        else
            typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1);

        switch (rs.getInt(5)) {
        case Types.STRUCT:
            dataType = new DataType(Types.STRUCT, typeName);
            dataType.setLocalTypeAndParams(structName, null);
            break;
        case Types.DISTINCT:
            dataType = new DataType(Types.DISTINCT, typeName);
            dataType.setLocalTypeAndParams(distinctName, null);
            break;
        case Types.JAVA_OBJECT:
            dataType = new DataType(Types.JAVA_OBJECT, typeName);
            dataType.setLocalTypeAndParams(javaName, null);
            break;
        }
        dataTypes.add(dataType);
    }

    return dataTypes;
}

From source file:at.bestsolution.persistence.java.Util.java

public static void setValue(PreparedStatement pstmt, int parameterIndex, TypedValue value) throws SQLException {
    if (value.value == null) {
        int sqlType;
        switch (value.type) {
        case INT:
            sqlType = Types.INTEGER;
            break;
        case DOUBLE:
            sqlType = Types.DECIMAL;
            break;
        case FLOAT:
            sqlType = Types.FLOAT;
            break;
        case BOOLEAN:
            sqlType = Types.BOOLEAN;
            break;
        case LONG:
            sqlType = Types.BIGINT;
            break;
        case STRING:
            sqlType = Types.VARCHAR;
            break;
        case BLOB:
            sqlType = Types.BLOB;
            break;
        case CLOB:
            sqlType = Types.CLOB;
            break;
        case TIMESTAMP:
            sqlType = Types.TIMESTAMP;
            break;
        default:/*from   w ww  .  j av  a  2  s . co m*/
            sqlType = Types.OTHER;
            break;
        }
        pstmt.setNull(parameterIndex, sqlType);
    } else {
        switch (value.type) {
        case INT:
            pstmt.setInt(parameterIndex, ((Number) value.value).intValue());
            break;
        case DOUBLE:
            pstmt.setDouble(parameterIndex, ((Number) value.value).doubleValue());
            break;
        case FLOAT:
            pstmt.setDouble(parameterIndex, ((Number) value.value).doubleValue());
            break;
        case BOOLEAN:
            pstmt.setBoolean(parameterIndex, Boolean.TRUE.equals(value.value));
            break;
        case LONG:
            pstmt.setLong(parameterIndex, ((Number) value.value).longValue());
            break;
        case STRING:
            pstmt.setString(parameterIndex, (String) value.value);
            break;
        case TIMESTAMP:
            if (value.value instanceof Timestamp) {
                pstmt.setTimestamp(parameterIndex, (Timestamp) value.value);
            } else {
                pstmt.setTimestamp(parameterIndex, new Timestamp(((Date) value.value).getTime()));
            }
            break;
        case UNKNOWN:
            pstmt.setObject(parameterIndex, value.value);
            break;
        default:
            throw new IllegalStateException("Unknown type");
        }
    }
}

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)
 *///  w ww  . ja  v  a2  s .  com
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.jumpmind.db.platform.oracle.OracleDdlReader.java

@Override
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException {
    Column column = super.readColumn(metaData, values);
    if (column.getMappedTypeCode() == Types.DECIMAL) {
        // We're back-mapping the NUMBER columns returned by Oracle
        // Note that the JDBC driver returns DECIMAL for these NUMBER
        // columns
        if (column.getScale() <= -127 || column.getScale() >= 127) {
            if (column.getSizeAsInt() == 0) {
                /*//from  w  ww.j  av a2  s.c o  m
                 * Latest oracle jdbc drivers for 11g return (0,-127) for
                 * types defined as integer resulting in bad mappings.
                 * NUMBER without scale or precision looks the same as
                 * INTEGER in the jdbc driver. We must check the Oracle
                 * meta data to see if type is an INTEGER.
                 */
                if (isColumnInteger((String) values.get("TABLE_NAME"), (String) values.get("COLUMN_NAME"))) {
                    column.setMappedTypeCode(Types.BIGINT);
                }
            } else if (column.getSizeAsInt() <= 63) {
                column.setMappedTypeCode(Types.REAL);
            } else {
                column.setMappedTypeCode(Types.DOUBLE);
            }
        }
    } else if (column.getMappedTypeCode() == Types.FLOAT) {
        // Same for REAL, FLOAT, DOUBLE PRECISION, which all back-map to
        // FLOAT but with
        // different sizes (63 for REAL, 126 for FLOAT/DOUBLE PRECISION)
        switch (column.getSizeAsInt()) {
        case 63:
            column.setMappedTypeCode(Types.REAL);
            break;
        case 126:
            column.setMappedTypeCode(Types.DOUBLE);
            break;
        }
    } else if ((column.getMappedTypeCode() == Types.DATE) || (column.getMappedTypeCode() == Types.TIMESTAMP)) {
        // we also reverse the ISO-format adaptation, and adjust the default
        // value to timestamp
        if (column.getDefaultValue() != null) {
            Timestamp timestamp = null;

            Matcher matcher = oracleIsoTimestampPattern.matcher(column.getDefaultValue());

            if (matcher.matches()) {
                String timestampVal = matcher.group(1);
                timestamp = Timestamp.valueOf(timestampVal);
            } else {
                matcher = oracleIsoDatePattern.matcher(column.getDefaultValue());
                if (matcher.matches()) {
                    String dateVal = matcher.group(1);
                    timestamp = new Timestamp(Date.valueOf(dateVal).getTime());
                } else {
                    matcher = oracleIsoTimePattern.matcher(column.getDefaultValue());
                    if (matcher.matches()) {
                        String timeVal = matcher.group(1);

                        timestamp = new Timestamp(Time.valueOf(timeVal).getTime());
                    }
                }
            }
            if (timestamp != null) {
                column.setDefaultValue(timestamp.toString());
            }
        }
    } else if (TypeMap.isTextType(column.getMappedTypeCode())) {
        String defaultValue = column.getDefaultValue();
        if (isNotBlank(defaultValue) && defaultValue.startsWith("('") && defaultValue.endsWith("')")) {
            defaultValue = defaultValue.substring(2, defaultValue.length() - 2);
        }
        column.setDefaultValue(unescape(defaultValue, "'", "''"));
    }
    return column;
}

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;
    }/*from   w ww  . j  a  v  a  2s .  co  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;
    }
    }
}

From source file:Main.java

private static Vector getDataTypes(Connection con) throws SQLException {
    String structName = null, distinctName = null, javaName = null;

    // create a vector of class DataType initialized with
    // the SQL code, the SQL type name, and two null entries
    // for the local type name and the creation parameter(s)

    Vector dataTypes = new Vector();
    dataTypes.add(new DataType(java.sql.Types.BIT, "BIT"));
    dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT"));
    dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT"));
    dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER"));
    dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT"));
    dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT"));
    dataTypes.add(new DataType(java.sql.Types.REAL, "REAL"));
    dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE"));
    dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC"));
    dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL"));
    dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR"));
    dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR"));
    dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR"));
    dataTypes.add(new DataType(java.sql.Types.DATE, "DATE"));
    dataTypes.add(new DataType(java.sql.Types.TIME, "TIME"));
    dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP"));
    dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY"));
    dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY"));
    dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY"));
    dataTypes.add(new DataType(java.sql.Types.NULL, "NULL"));
    dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER"));
    dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB"));
    dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB"));

    DatabaseMetaData dbmd = con.getMetaData();
    ResultSet rs = dbmd.getTypeInfo();
    while (rs.next()) {
        int codeNumber = rs.getInt("DATA_TYPE");
        String dbmsName = rs.getString("TYPE_NAME");
        String createParams = rs.getString("CREATE_PARAMS");

        if (codeNumber == Types.STRUCT && structName == null)
            structName = dbmsName;//  w w  w. ja va 2  s .  c o  m
        else if (codeNumber == Types.DISTINCT && distinctName == null)
            distinctName = dbmsName;
        else if (codeNumber == Types.JAVA_OBJECT && javaName == null)
            javaName = dbmsName;
        else {
            for (int i = 0; i < dataTypes.size(); i++) {
                // find entry that matches the SQL code,
                // and if local type and params are not already set,
                // set them
                DataType type = (DataType) dataTypes.get(i);
                if (type.getCode() == codeNumber) {
                    type.setLocalTypeAndParams(dbmsName, createParams);
                }
            }
        }
    }

    int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT };
    rs = dbmd.getUDTs(null, "%", "%", types);
    while (rs.next()) {
        String typeName = null;
        DataType dataType = null;

        if (dbmd.isCatalogAtStart())
            typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3);
        else
            typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1);

        switch (rs.getInt(5)) {
        case Types.STRUCT:
            dataType = new DataType(Types.STRUCT, typeName);
            dataType.setLocalTypeAndParams(structName, null);
            break;
        case Types.DISTINCT:
            dataType = new DataType(Types.DISTINCT, typeName);
            dataType.setLocalTypeAndParams(distinctName, null);
            break;
        case Types.JAVA_OBJECT:
            dataType = new DataType(Types.JAVA_OBJECT, typeName);
            dataType.setLocalTypeAndParams(javaName, null);
            break;
        }
        dataTypes.add(dataType);
    }

    return dataTypes;
}

From source file:CSVWriter.java

private static String getColumnValue(ResultSet rs, int colType, int colIndex)
    throws SQLException, IOException {

  String value = "";
      //from w w  w .j ava2 s  .co m
switch (colType)
{
  case Types.BIT:
    Object bit = rs.getObject(colIndex);
    if (bit != null) {
      value = String.valueOf(bit);
    }
  break;
  case Types.BOOLEAN:
    boolean b = rs.getBoolean(colIndex);
    if (!rs.wasNull()) {
      value = Boolean.valueOf(b).toString();
    }
  break;
  case Types.CLOB:
    Clob c = rs.getClob(colIndex);
    if (c != null) {
      value = read(c);
    }
  break;
  case Types.BIGINT:
  case Types.DECIMAL:
  case Types.DOUBLE:
  case Types.FLOAT:
  case Types.REAL:
  case Types.NUMERIC:
    BigDecimal bd = rs.getBigDecimal(colIndex);
    if (bd != null) {
      value = "" + bd.doubleValue();
    }
  break;
  case Types.INTEGER:
  case Types.TINYINT:
  case Types.SMALLINT:
    int intValue = rs.getInt(colIndex);
    if (!rs.wasNull()) {
      value = "" + intValue;
    }
  break;
  case Types.JAVA_OBJECT:
    Object obj = rs.getObject(colIndex);
    if (obj != null) {
      value = String.valueOf(obj);
    }
  break;
  case Types.DATE:
    java.sql.Date date = rs.getDate(colIndex);
    if (date != null) {
      value = DATE_FORMATTER.format(date);;
    }
  break;
  case Types.TIME:
    Time t = rs.getTime(colIndex);
    if (t != null) {
      value = t.toString();
    }
  break;
  case Types.TIMESTAMP:
    Timestamp tstamp = rs.getTimestamp(colIndex);
    if (tstamp != null) {
      value = TIMESTAMP_FORMATTER.format(tstamp);
    }
  break;
  case Types.LONGVARCHAR:
  case Types.VARCHAR:
  case Types.CHAR:
    value = rs.getString(colIndex);
  break;
  default:
    value = "";
}

    
if (value == null)
{
  value = "";
}
    
return value;
      
}