Example usage for java.sql Types CLOB

List of usage examples for java.sql Types CLOB

Introduction

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

Prototype

int CLOB

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

Click Source Link

Document

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

Usage

From source file:it.greenvulcano.gvesb.utils.GVESBPropertyHandler.java

private String expandSQLProperties(String str, Map<String, Object> inProperties, Object object, Object extra)
        throws PropertiesHandlerException {
    PreparedStatement ps = null;//w w  w.  j a  v  a2  s.  c om
    ResultSet rs = null;
    String sqlStatement = null;
    Connection conn = null;
    String connName = "";
    boolean intConn = false;
    try {
        if (!PropertiesHandler.isExpanded(str)) {
            str = PropertiesHandler.expand(str, inProperties, object, extra);
        }
        int pIdx = str.indexOf("::");
        if (pIdx != -1) {
            connName = str.substring(0, pIdx);
            sqlStatement = str.substring(pIdx + 2);
            intConn = true;
        } else {
            sqlStatement = str;
        }
        if (intConn) {
            conn = JDBCConnectionBuilder.getConnection(connName);
        } else if ((extra != null) && (extra instanceof Connection)) {
            conn = (Connection) extra;
        } else {
            throw new PropertiesHandlerException(
                    "Error handling 'sql' metadata '" + str + "', Connection undefined.");
        }
        logger.debug("Executing SQL statement {" + sqlStatement + "} on connection [" + connName + "]");
        ps = conn.prepareStatement(sqlStatement);
        rs = ps.executeQuery();

        String paramValue = null;

        if (rs.next()) {
            ResultSetMetaData rsmeta = rs.getMetaData();
            if (rsmeta.getColumnType(1) == Types.CLOB) {
                Clob clob = rs.getClob(1);
                if (clob != null) {
                    Reader is = clob.getCharacterStream();
                    StringWriter strW = new StringWriter();

                    IOUtils.copy(is, strW);
                    is.close();
                    paramValue = strW.toString();
                }
            } else {
                paramValue = rs.getString(1);
            }
        }

        return (paramValue != null) ? paramValue.trim() : paramValue;
    } catch (Exception exc) {
        logger.warn("Error handling 'sql' metadata '" + sqlStatement + "'", exc);
        if (PropertiesHandler.isExceptionOnErrors()) {
            if (exc instanceof PropertiesHandlerException) {
                throw (PropertiesHandlerException) exc;
            }
            throw new PropertiesHandlerException("Error handling 'sql' metadata '" + str + "'", exc);
        }
        return "sql" + PROP_START + str + PROP_END;
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (Exception exc) {
                // do nothing
            }
        }
        if (ps != null) {
            try {
                ps.close();
            } catch (Exception exc) {
                // do nothing
            }
        }
        if (intConn && (conn != null)) {
            try {
                JDBCConnectionBuilder.releaseConnection(connName, conn);
            } catch (Exception exc) {
                // do nothing
            }
        }
    }
}

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 w  w.  ja  va2 s .  c  om*/
            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.xsystem.sql2.dml.DmlCommand.java

Object getValue(Object retValue, int jdbcType, String objectType, Connection con,
        AbstactNativeHelper nativeHelper) throws SQLException {
    if (jdbcType == Types.ARRAY && retValue != null) {
        Array array = (Array) retValue;
        retValue = nativeHelper.createList(con, array, objectType);
    } else if (jdbcType == Types.STRUCT && retValue != null) {
        Struct structValue = (Struct) retValue;
        retValue = nativeHelper.createMap(con, structValue, objectType);
    } else if (jdbcType == Types.BLOB && retValue != null) {
        Blob blob = (Blob) retValue;
        retValue = getBlob(blob);//from  w w w .  j  ava  2s . c o  m
    } else if (jdbcType == Types.CLOB && retValue != null) {
        Clob clob = (Clob) retValue;
        retValue = getClob(clob);
    } else if (jdbcType == Types.OTHER && retValue != null) {
        retValue = nativeHelper.getOTHER(con, retValue);
    }
    return retValue;
}

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

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type.spec) {
    case STRING://w ww . j av  a2s.co  m
        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 ARRAY_STRING:
        if (type.isUnconstrained()) {
            return jdbcInfo("varchar[]", Types.ARRAY, "varchar", Types.VARCHAR);
        } else if (type.isClob()) {
            return jdbcInfo("text[]", Types.ARRAY, "text", Types.CLOB);
        } else {
            return jdbcInfo("varchar(%d)[]", type.length, Types.ARRAY, "varchar", Types.VARCHAR);
        }
    case BOOLEAN:
        return jdbcInfo("bool", Types.BIT);
    case ARRAY_BOOLEAN:
        return jdbcInfo("bool[]", Types.ARRAY, "bool", Types.BOOLEAN);
    case LONG:
        return jdbcInfo("int8", Types.BIGINT);
    case ARRAY_LONG:
        return jdbcInfo("int8[]", Types.ARRAY, "int8", Types.BIGINT);
    case DOUBLE:
        return jdbcInfo("float8", Types.DOUBLE);
    case ARRAY_DOUBLE:
        return jdbcInfo("float8[]", Types.ARRAY, "float8", Types.DOUBLE);
    case TIMESTAMP:
        return jdbcInfo("timestamp", Types.TIMESTAMP);
    case ARRAY_TIMESTAMP:
        return jdbcInfo("timestamp[]", Types.ARRAY, "timestamp", Types.TIMESTAMP);
    case BLOBID:
        return jdbcInfo("varchar(40)", Types.VARCHAR);
    case ARRAY_BLOBID:
        return jdbcInfo("varchar(40)[]", Types.ARRAY, "varchar", Types.VARCHAR);
    // -----
    case NODEID:
    case NODEIDFK:
    case NODEIDFKNP:
    case NODEIDFKMUL:
    case NODEIDFKNULL:
    case NODEIDPK:
    case NODEVAL:
        switch (idType) {
        case VARCHAR:
            return jdbcInfo("varchar(36)", Types.VARCHAR);
        case UUID:
            return jdbcInfo("uuid", Types.OTHER);
        case SEQUENCE:
            return jdbcInfo("int8", Types.BIGINT);
        }
    case NODEARRAY:
        switch (idType) {
        case VARCHAR:
            return jdbcInfo("varchar(36)[]", Types.ARRAY, "varchar", Types.VARCHAR);
        case UUID:
            return jdbcInfo("uuid[]", Types.ARRAY, "uuid", Types.OTHER);
        case SEQUENCE:
            return jdbcInfo("int8[]", Types.ARRAY, "int8", Types.BIGINT);
        }
    case SYSNAME:
        return jdbcInfo("varchar(250)", Types.VARCHAR);
    case SYSNAMEARRAY:
        return jdbcInfo("varchar(250)[]", Types.ARRAY, "varchar", Types.VARCHAR);
    case TINYINT:
        return jdbcInfo("int2", Types.SMALLINT);
    case INTEGER:
        return jdbcInfo("int4", Types.INTEGER);
    case ARRAY_INTEGER:
        return jdbcInfo("int4[]", Types.ARRAY, "int4", Types.INTEGER);
    case AUTOINC:
        return jdbcInfo("serial", Types.INTEGER);
    case FTINDEXED:
        if (compatibilityFulltextTable) {
            return jdbcInfo("tsvector", Types.OTHER);
        } else {
            return jdbcInfo("text", Types.CLOB);
        }
    case FTSTORED:
        if (compatibilityFulltextTable) {
            return jdbcInfo("tsvector", Types.OTHER);
        } else {
            return jdbcInfo("text", Types.CLOB);
        }
    case CLUSTERNODE:
        return jdbcInfo("int4", Types.INTEGER);
    case CLUSTERFRAGS:
        return jdbcInfo("varchar[]", Types.ARRAY, "varchar", Types.VARCHAR);
    }
    throw new AssertionError(type);
}

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

@Override
@SuppressWarnings("boxing")
public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException {
    switch (column.getJdbcType()) {
    case Types.VARCHAR:
        return getFromResultSetString(rs, index, column);
    case Types.CLOB:
        // Oracle cannot read CLOBs using rs.getString when the ResultSet is
        // a ScrollableResultSet (the standard OracleResultSetImpl works
        // fine).
        Reader r = rs.getCharacterStream(index);
        if (r == null) {
            return null;
        }/*  w  w  w . j av a  2 s. c  o  m*/
        StringBuilder sb = new StringBuilder();
        try {
            int n;
            char[] buffer = new char[4096];
            while ((n = r.read(buffer)) != -1) {
                sb.append(new String(buffer, 0, n));
            }
        } catch (IOException e) {
            log.error("Cannot read CLOB", e);
        }
        return sb.toString();
    case Types.BIT:
        return rs.getBoolean(index);
    case Types.TINYINT:
    case Types.SMALLINT:
    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);
    }
    throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
}

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

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type.spec) {
    case STRING://from  ww  w.  j  a  v a  2 s . c om
        if (type.isUnconstrained()) {
            return jdbcInfo("NVARCHAR(4000)", Types.VARCHAR);
        } else if (type.isClob() || type.length > 4000) {
            return jdbcInfo("NVARCHAR(MAX)", Types.CLOB);
        } else {
            return jdbcInfo("NVARCHAR(%d)", type.length, Types.VARCHAR);
        }
    case BOOLEAN:
        return jdbcInfo("BIT", Types.BIT);
    case LONG:
        return jdbcInfo("BIGINT", Types.BIGINT);
    case DOUBLE:
        return jdbcInfo("DOUBLE PRECISION", Types.DOUBLE);
    case TIMESTAMP:
        return jdbcInfo("DATETIME", Types.TIMESTAMP);
    case BLOBID:
        return jdbcInfo("NVARCHAR(40)", Types.VARCHAR);
    // -----
    case NODEID:
    case NODEIDFK:
    case NODEIDFKNP:
    case NODEIDFKMUL:
    case NODEIDFKNULL:
    case NODEIDPK:
    case NODEVAL:
        switch (idType) {
        case VARCHAR:
            return jdbcInfo("NVARCHAR(36)", Types.VARCHAR);
        case SEQUENCE:
            return jdbcInfo("BIGINT", Types.BIGINT);
        }
    case SYSNAME:
    case SYSNAMEARRAY:
        return jdbcInfo("NVARCHAR(256)", Types.VARCHAR);
    case TINYINT:
        return jdbcInfo("TINYINT", Types.TINYINT);
    case INTEGER:
        return jdbcInfo("INT", Types.INTEGER);
    case AUTOINC:
        return jdbcInfo("INT IDENTITY", Types.INTEGER);
    case FTINDEXED:
        throw new AssertionError(type);
    case FTSTORED:
        return jdbcInfo("NVARCHAR(MAX)", Types.CLOB);
    case CLUSTERNODE:
        return jdbcInfo("SMALLINT", Types.SMALLINT);
    case CLUSTERFRAGS:
        return jdbcInfo("NVARCHAR(4000)", Types.VARCHAR);
    }
    throw new AssertionError(type);
}

From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectPostgreSQL.java

@Override
@SuppressWarnings("boxing")
public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException {
    switch (column.getJdbcType()) {
    case Types.VARCHAR:
    case Types.CLOB:
        String string = rs.getString(index);
        if (column.getType() == ColumnType.BLOBID && string != null) {
            return column.getModel().getBinary(string);
        } else {/* ww w.j  a v a  2  s.  c o  m*/
            return string;
        }
    case Types.BIT:
        return rs.getBoolean(index);
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
        return rs.getLong(index);
    case Types.DOUBLE:
        return rs.getDouble(index);
    case Types.TIMESTAMP:
        Timestamp ts = rs.getTimestamp(index);
        if (ts == null) {
            return null;
        } else {
            Serializable cal = new GregorianCalendar(); // XXX timezone
            ((Calendar) cal).setTimeInMillis(ts.getTime());
            return cal;
        }
    case Types.ARRAY:
        return (Serializable) rs.getArray(index).getArray();
    }
    throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
}

From source file:org.moqui.impl.entity.EntityJavaUtil.java

public static Object getResultSetValue(ResultSet rs, int index, FieldInfo fi, EntityFacade efi)
        throws EntityException {
    if (fi.typeValue == -1)
        throw new EntityException("No typeValue found for " + fi.entityName + "." + fi.name);

    Object value = null;/*from www .j  a  v a2s .com*/
    try {
        switch (fi.typeValue) {
        case 1:
            // getMetaData and the column type are somewhat slow (based on profiling), and String values are VERY
            //     common, so only do for text-very-long
            if (fi.isTextVeryLong) {
                ResultSetMetaData rsmd = rs.getMetaData();
                if (Types.CLOB == rsmd.getColumnType(index)) {
                    // if the String is empty, try to get a text input stream, this is required for some databases
                    // for larger fields, like CLOBs
                    Clob valueClob = rs.getClob(index);
                    Reader valueReader = null;
                    if (valueClob != null)
                        valueReader = valueClob.getCharacterStream();
                    if (valueReader != null) {
                        // read up to 4096 at a time
                        char[] inCharBuffer = new char[4096];
                        StringBuilder strBuf = new StringBuilder();
                        try {
                            int charsRead;
                            while ((charsRead = valueReader.read(inCharBuffer, 0, 4096)) > 0) {
                                strBuf.append(inCharBuffer, 0, charsRead);
                            }
                            valueReader.close();
                        } catch (IOException e) {
                            throw new EntityException("Error reading long character stream for field ["
                                    + fi.name + "] of entity [" + fi.entityName + "]", e);
                        }
                        value = strBuf.toString();
                    }
                } else {
                    value = rs.getString(index);
                }
            } else {
                value = rs.getString(index);
            }
            break;
        case 2:
            try {
                value = rs.getTimestamp(index, efi.getCalendarForTzLc());
            } catch (SQLException e) {
                if (logger.isTraceEnabled())
                    logger.trace(
                            "Ignoring SQLException for getTimestamp(), leaving null (found this in MySQL with a date/time value of [0000-00-00 00:00:00]): "
                                    + e.toString());
            }
            break;
        case 3:
            value = rs.getTime(index, efi.getCalendarForTzLc());
            break;
        case 4:
            value = rs.getDate(index, efi.getCalendarForTzLc());
            break;
        case 5:
            int intValue = rs.getInt(index);
            if (!rs.wasNull())
                value = intValue;
            break;
        case 6:
            long longValue = rs.getLong(index);
            if (!rs.wasNull())
                value = longValue;
            break;
        case 7:
            float floatValue = rs.getFloat(index);
            if (!rs.wasNull())
                value = floatValue;
            break;
        case 8:
            double doubleValue = rs.getDouble(index);
            if (!rs.wasNull())
                value = doubleValue;
            break;
        case 9:
            BigDecimal bigDecimalValue = rs.getBigDecimal(index);
            if (!rs.wasNull())
                value = bigDecimalValue != null ? bigDecimalValue.stripTrailingZeros() : null;
            break;
        case 10:
            boolean booleanValue = rs.getBoolean(index);
            if (!rs.wasNull())
                value = booleanValue;
            break;
        case 11:
            Object obj = null;
            byte[] originalBytes = rs.getBytes(index);
            InputStream binaryInput = null;
            if (originalBytes != null && originalBytes.length > 0) {
                binaryInput = new ByteArrayInputStream(originalBytes);
            }
            if (originalBytes != null && originalBytes.length <= 0) {
                logger.warn("Got byte array back empty for serialized Object with length ["
                        + originalBytes.length + "] for field [" + fi.name + "] (" + index + ")");
            }
            if (binaryInput != null) {
                ObjectInputStream inStream = null;
                try {
                    inStream = new ObjectInputStream(binaryInput);
                    obj = inStream.readObject();
                } catch (IOException ex) {
                    if (logger.isTraceEnabled())
                        logger.trace("Unable to read BLOB from input stream for field [" + fi.name + "] ("
                                + index + "): " + ex.toString());
                } catch (ClassNotFoundException ex) {
                    if (logger.isTraceEnabled())
                        logger.trace("Class not found: Unable to cast BLOB data to an Java object for field ["
                                + fi.name + "] (" + index
                                + "); most likely because it is a straight byte[], so just using the raw bytes: "
                                + ex.toString());
                } finally {
                    if (inStream != null) {
                        try {
                            inStream.close();
                        } catch (IOException e) {
                            throw new EntityException("Unable to close binary input stream for field ["
                                    + fi.name + "] (" + index + "): " + e.toString(), e);
                        }
                    }
                }
            }
            if (obj != null) {
                value = obj;
            } else {
                value = originalBytes;
            }
            break;
        case 12:
            SerialBlob sblob = null;
            try {
                // NOTE: changed to try getBytes first because Derby blows up on getBlob and on then calling getBytes for the same field, complains about getting value twice
                byte[] fieldBytes = rs.getBytes(index);
                if (!rs.wasNull())
                    sblob = new SerialBlob(fieldBytes);
                // fieldBytes = theBlob != null ? theBlob.getBytes(1, (int) theBlob.length()) : null
            } catch (SQLException e) {
                if (logger.isTraceEnabled())
                    logger.trace("Ignoring exception trying getBytes(), trying getBlob(): " + e.toString());
                Blob theBlob = rs.getBlob(index);
                if (!rs.wasNull())
                    sblob = new SerialBlob(theBlob);
            }
            value = sblob;
            break;
        case 13:
            value = new SerialClob(rs.getClob(index));
            break;
        case 14:
        case 15:
            value = rs.getObject(index);
            break;
        }
    } catch (SQLException sqle) {
        logger.error("SQL Exception while getting value for field: [" + fi.name + "] (" + index + ")", sqle);
        throw new EntityException(
                "SQL Exception while getting value for field: [" + fi.name + "] (" + index + ")", sqle);
    }

    return value;
}

From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectPostgreSQL.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.SMALLINT:
    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);
    case Types.ARRAY:
        Array array = rs.getArray(index);
        return array == null ? null : (Serializable) array.getArray();
    }/* w  ww  .  j  a  v a 2  s.c  o  m*/
    throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
}

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;//  w  ww . java2  s  .co  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;
}