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:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type.spec) {
    case STRING:/*w  w w. j  a  v a  2 s . c o m*/
        if (type.isUnconstrained()) {
            return jdbcInfo("NVARCHAR2(2000)", Types.VARCHAR);
        } else if (type.isClob() || type.length > 2000) {
            return jdbcInfo("NCLOB", Types.CLOB);
        } else {
            return jdbcInfo("NVARCHAR2(%d)", type.length, Types.VARCHAR);
        }
    case BOOLEAN:
        return jdbcInfo("NUMBER(1,0)", Types.BIT);
    case LONG:
        return jdbcInfo("NUMBER(19,0)", Types.BIGINT);
    case DOUBLE:
        return jdbcInfo("DOUBLE PRECISION", Types.DOUBLE);
    case TIMESTAMP:
        return jdbcInfo("TIMESTAMP", Types.TIMESTAMP);
    case BLOBID:
        return jdbcInfo("VARCHAR2(40)", Types.VARCHAR);
    // -----
    case NODEID:
    case NODEIDFK:
    case NODEIDFKNP:
    case NODEIDFKMUL:
    case NODEIDFKNULL:
    case NODEIDPK:
    case NODEVAL:
        return jdbcInfo("VARCHAR2(36)", Types.VARCHAR);
    case SYSNAME:
    case SYSNAMEARRAY:
        return jdbcInfo("VARCHAR2(250)", Types.VARCHAR);
    case TINYINT:
        return jdbcInfo("NUMBER(3,0)", Types.TINYINT);
    case INTEGER:
        return jdbcInfo("NUMBER(10,0)", Types.INTEGER);
    case FTINDEXED:
        return jdbcInfo("CLOB", Types.CLOB);
    case FTSTORED:
        return jdbcInfo("NCLOB", Types.CLOB);
    case CLUSTERNODE:
        return jdbcInfo("NUMBER(10,0)", Types.INTEGER);
    case CLUSTERFRAGS:
        return jdbcInfo("VARCHAR2(4000)", Types.VARCHAR);
    }
    throw new AssertionError(type);
}

From source file:com.squid.core.jdbc.formatter.DefaultJDBCDataFormatter.java

public String formatJDBCObject(final Object jdbcObject, final int colType) throws SQLException {
    String value = "";

    switch (colType) {
    case Types.BIT:
        if (jdbcObject != null) {
            value = String.valueOf(jdbcObject);
        }/*from   ww w.j  a va  2  s.  c om*/
        break;
    case Types.BOOLEAN:
        if (jdbcObject != null) {
            value = new Boolean(jdbcObject.toString()).toString();
        }
        break;
    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.REAL:
    case Types.NUMERIC:
        if (jdbcObject != null) {
            value = "" + formatter.formatDecimal(jdbcObject);
        }
        break;
    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
        if (jdbcObject != null) {
            value = "" + formatter.formatDecimal(jdbcObject);
        }
        break;
    case Types.CLOB:
        if (jdbcObject != null) {
            try {
                value = read((Clob) jdbcObject);
            } catch (SQLException sqle) {
                value = "";
            } catch (IOException ioe) {
                value = "";
            }
        }
        break;
    case Types.ARRAY:
        try {
            ResultSet rs = ((Array) jdbcObject).getResultSet();
            int arrayType = ((Array) jdbcObject).getBaseType();
            boolean isNotNew = false;
            while (rs.next()) {
                String current = formatJDBCObject(rs.getObject(2), arrayType);
                if ("".equals(current.trim()) == false) {
                    if (isNotNew) {
                        value = value + ",";
                    } else {
                        isNotNew = !isNotNew;
                    }
                    value = value + current;
                }
            }
            if ("".equals(value) == false) {
                value = "{" + value + "}";
            }
        } catch (SQLException sqle) {
            value = "";
        }
        break;
    case Types.JAVA_OBJECT:
        if (jdbcObject != null) {
            value = String.valueOf(jdbcObject);
        }
        break;
    case Types.DATE:
        if (jdbcObject != null) {
            value = formatter.formatDate(jdbcObject);
        }
        break;
    case Types.TIME:
        if (jdbcObject != null) {
            value = ((Time) jdbcObject).toString();
        }
        break;
    case Types.TIMESTAMP:
        if (jdbcObject != null) {
            value = formatter.formatTimestamp(jdbcObject);
        }
        break;
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
    case Types.CHAR:
        if (jdbcObject != null) {
            value = jdbcObject.toString();
        } else {
            value = "NULL";
        }
        break;
    case Types.BINARY:
        value = new String((byte[]) jdbcObject);
        break;
    default:
        value = "";
    }
    if (value == null) {
        value = "";
    }
    return value;
}

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

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type) {
    case VARCHAR:
        return jdbcInfo("NVARCHAR2(2000)", Types.VARCHAR);
    case CLOB:/*www  . j a  v  a  2 s. c om*/
        return jdbcInfo("NCLOB", Types.CLOB);
    case BOOLEAN:
        return jdbcInfo("NUMBER(1,0)", Types.BIT);
    case LONG:
        return jdbcInfo("NUMBER(19,0)", Types.BIGINT);
    case DOUBLE:
        return jdbcInfo("DOUBLE PRECISION", Types.DOUBLE);
    case TIMESTAMP:
        return jdbcInfo("TIMESTAMP", Types.TIMESTAMP);
    case BLOBID:
        return jdbcInfo("VARCHAR2(40)", Types.VARCHAR);
    // -----
    case NODEID:
    case NODEIDFK:
    case NODEIDFKNP:
    case NODEIDFKMUL:
    case NODEIDFKNULL:
    case NODEVAL:
        return jdbcInfo("VARCHAR2(36)", Types.VARCHAR);
    case SYSNAME:
        return jdbcInfo("VARCHAR2(250)", Types.VARCHAR);
    case TINYINT:
        return jdbcInfo("NUMBER(3,0)", Types.TINYINT);
    case INTEGER:
        return jdbcInfo("NUMBER(10,0)", Types.INTEGER);
    case FTINDEXED:
        return jdbcInfo("CLOB", Types.CLOB);
    case FTSTORED:
        return jdbcInfo("NCLOB", Types.CLOB);
    case CLUSTERNODE:
        return jdbcInfo("NUMBER(10,0)", Types.INTEGER);
    case CLUSTERFRAGS:
        return jdbcInfo("VARCHAR2(4000)", Types.VARCHAR);
    }
    throw new AssertionError(type);
}

From source file:org.apache.openjpa.jdbc.schema.Schemas.java

/**
 * Return the {@link Types} constant for the given SQL type name.
 *///from w  w w . j av a 2s. c o m
public static int getJDBCType(String name) {
    if ("array".equalsIgnoreCase(name))
        return Types.ARRAY;
    if ("bigint".equalsIgnoreCase(name))
        return Types.BIGINT;
    if ("binary".equalsIgnoreCase(name))
        return Types.BINARY;
    if ("bit".equalsIgnoreCase(name))
        return Types.BIT;
    if ("blob".equalsIgnoreCase(name))
        return Types.BLOB;
    if ("char".equalsIgnoreCase(name))
        return Types.CHAR;
    if ("clob".equalsIgnoreCase(name))
        return Types.CLOB;
    if ("date".equalsIgnoreCase(name))
        return Types.DATE;
    if ("decimal".equalsIgnoreCase(name))
        return Types.DECIMAL;
    if ("distinct".equalsIgnoreCase(name))
        return Types.DISTINCT;
    if ("double".equalsIgnoreCase(name))
        return Types.DOUBLE;
    if ("float".equalsIgnoreCase(name))
        return Types.FLOAT;
    if ("integer".equalsIgnoreCase(name))
        return Types.INTEGER;
    if ("java_object".equalsIgnoreCase(name))
        return Types.JAVA_OBJECT;
    if ("longvarbinary".equalsIgnoreCase(name))
        return Types.LONGVARBINARY;
    if ("longvarchar".equalsIgnoreCase(name))
        return Types.LONGVARCHAR;
    if ("null".equalsIgnoreCase(name))
        return Types.NULL;
    if ("numeric".equalsIgnoreCase(name))
        return Types.NUMERIC;
    if ("other".equalsIgnoreCase(name))
        return Types.OTHER;
    if ("real".equalsIgnoreCase(name))
        return Types.REAL;
    if ("ref".equalsIgnoreCase(name))
        return Types.REF;
    if ("smallint".equalsIgnoreCase(name))
        return Types.SMALLINT;
    if ("struct".equalsIgnoreCase(name))
        return Types.STRUCT;
    if ("time".equalsIgnoreCase(name))
        return Types.TIME;
    if ("timestamp".equalsIgnoreCase(name))
        return Types.TIMESTAMP;
    if ("tinyint".equalsIgnoreCase(name))
        return Types.TINYINT;
    if ("varbinary".equalsIgnoreCase(name))
        return Types.VARBINARY;
    if ("varchar".equalsIgnoreCase(name))
        return Types.VARCHAR;
    if (name == null || name.toLowerCase().startsWith("unknown"))
        return Types.OTHER;
    throw new IllegalArgumentException("name = " + name);
}

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   www.  ja  v  a 2  s .c  om*/
    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:org.apache.ddlutils.platform.sybase.SybasePlatform.java

/**
 * Creates a new platform instance.//  w w  w  .ja  va  2 s  .co  m
 */
public SybasePlatform() {
    PlatformInfo info = getPlatformInfo();

    info.setMaxIdentifierLength(28);
    info.setNullAsDefaultValueRequired(true);
    info.setIdentityColumnAutomaticallyRequired(true);
    info.setMultipleIdentityColumnsSupported(false);
    info.setPrimaryKeyColumnsHaveToBeRequired(true);
    info.setCommentPrefix("/*");
    info.setCommentSuffix("*/");

    info.addNativeTypeMapping(Types.ARRAY, "IMAGE");
    // BIGINT is mapped back in the model reader
    info.addNativeTypeMapping(Types.BIGINT, "DECIMAL(19,0)");
    // we're not using the native BIT type because it is rather limited (cannot be NULL, cannot be indexed)
    info.addNativeTypeMapping(Types.BIT, "SMALLINT", Types.SMALLINT);
    info.addNativeTypeMapping(Types.BLOB, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.BOOLEAN, "SMALLINT", Types.SMALLINT);
    info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR);
    info.addNativeTypeMapping(Types.DATALINK, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DATE, "DATETIME", Types.TIMESTAMP);
    info.addNativeTypeMapping(Types.DISTINCT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DOUBLE, "DOUBLE PRECISION");
    info.addNativeTypeMapping(Types.FLOAT, "DOUBLE PRECISION", Types.DOUBLE);
    info.addNativeTypeMapping(Types.INTEGER, "INT");
    info.addNativeTypeMapping(Types.JAVA_OBJECT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.LONGVARBINARY, "IMAGE");
    info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT");
    info.addNativeTypeMapping(Types.NULL, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.OTHER, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.REF, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.STRUCT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.TIME, "DATETIME", Types.TIMESTAMP);
    info.addNativeTypeMapping(Types.TIMESTAMP, "DATETIME", Types.TIMESTAMP);
    info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT);

    info.setDefaultSize(Types.BINARY, 254);
    info.setDefaultSize(Types.VARBINARY, 254);
    info.setDefaultSize(Types.CHAR, 254);
    info.setDefaultSize(Types.VARCHAR, 254);

    setSqlBuilder(new SybaseBuilder(this));
    setModelReader(new SybaseModelReader(this));
}

From source file:com.feedzai.commons.sql.abstraction.engine.impl.PostgreSqlEngine.java

@Override
protected int entityToPreparedStatement(final DbEntity entity, final PreparedStatement ps,
        final EntityEntry entry, final boolean useAutoInc) throws DatabaseEngineException {

    int i = 1;/*from   www.java 2s .  c  o  m*/
    for (DbColumn column : entity.getColumns()) {
        if (column.isAutoInc() && useAutoInc) {
            continue;
        }

        try {
            final Object val;
            if (column.isDefaultValueSet() && !entry.containsKey(column.getName())) {
                val = column.getDefaultValue().getConstant();
            } else {
                val = entry.get(column.getName());
            }

            switch (column.getDbColumnType()) {
            case BLOB:
                ps.setBytes(i, objectToArray(val));

                break;
            case CLOB:
                if (val == null) {
                    ps.setNull(i, Types.CLOB);
                    break;
                }

                if (val instanceof String) {
                    //StringReader sr = new StringReader((String) val);
                    //ps.setClob(i, sr);
                    // postrgresql driver des not have setClob implemented
                    ps.setString(i, (String) val);
                } else {
                    throw new DatabaseEngineException("Cannot convert " + val.getClass().getSimpleName()
                            + " to String. CLOB columns only accept Strings.");
                }
                break;
            default:
                ps.setObject(i, val);
            }
        } catch (Exception ex) {
            throw new DatabaseEngineException("Error while mapping variables to database", ex);
        }

        i++;
    }

    return i - 1;
}

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

/**
 * Creates a new platform instance.//from   w  w w . j  a va 2 s. com
 */
public MSSqlPlatform() {
    PlatformInfo info = getPlatformInfo();

    info.setMaxIdentifierLength(128);
    info.setPrimaryKeyColumnAutomaticallyRequired(true);
    info.setIdentityColumnAutomaticallyRequired(true);
    info.setMultipleIdentityColumnsSupported(false);
    info.setSupportedOnUpdateActions(
            new CascadeActionEnum[] { CascadeActionEnum.CASCADE, CascadeActionEnum.NONE });
    info.addEquivalentOnUpdateActions(CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT);
    info.setSupportedOnDeleteActions(
            new CascadeActionEnum[] { CascadeActionEnum.CASCADE, CascadeActionEnum.NONE });
    info.addEquivalentOnDeleteActions(CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT);

    info.addNativeTypeMapping(Types.ARRAY, "IMAGE", Types.LONGVARBINARY);
    // BIGINT will be mapped back to BIGINT by the model reader 
    info.addNativeTypeMapping(Types.BIGINT, "DECIMAL(19,0)");
    info.addNativeTypeMapping(Types.BLOB, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.BOOLEAN, "BIT", Types.BIT);
    info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR);
    info.addNativeTypeMapping(Types.DATALINK, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DATE, "DATETIME", Types.TIMESTAMP);
    info.addNativeTypeMapping(Types.DISTINCT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DOUBLE, "FLOAT", Types.FLOAT);
    info.addNativeTypeMapping(Types.INTEGER, "INT");
    info.addNativeTypeMapping(Types.JAVA_OBJECT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.LONGVARBINARY, "IMAGE");
    info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT");
    info.addNativeTypeMapping(Types.NULL, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.OTHER, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.REF, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.STRUCT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.TIME, "DATETIME", Types.TIMESTAMP);
    info.addNativeTypeMapping(Types.TIMESTAMP, "DATETIME");
    info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT);

    info.setDefaultSize(Types.CHAR, 254);
    info.setDefaultSize(Types.VARCHAR, 254);
    info.setDefaultSize(Types.BINARY, 254);
    info.setDefaultSize(Types.VARBINARY, 254);

    setSqlBuilder(new MSSqlBuilder(this));
    setModelReader(new MSSqlModelReader(this));
}

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

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type) {
    case VARCHAR:
        return jdbcInfo("varchar", Types.VARCHAR);
    case CLOB:/*  w  w  w . j ava  2s  .com*/
        return jdbcInfo("text", Types.CLOB);
    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 NODEVAL:
        return jdbcInfo("varchar(36)", Types.VARCHAR);
    case SYSNAME:
        return jdbcInfo("varchar(250)", Types.VARCHAR);
    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.openmrs.module.sync.api.db.hibernate.usertype.SyncItemListSerializingUserType.java

/**
 * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int)
 *///ww  w . ja v  a2s .  c  o m
@SuppressWarnings("unchecked")
public void nullSafeSet(PreparedStatement ps, Object value, int index) throws HibernateException, SQLException {
    if (value == null) {
        ps.setNull(index, Types.CLOB);
    } else if (value instanceof String) {
        // if the user is doing a search of the payload items
        ps.setString(index, (String) value);
    } else {
        Collection<SyncItem> items = (Collection<SyncItem>) value;

        Package pkg = new Package();
        Record record;
        try {
            record = pkg.createRecordForWrite("items");
            Item root = record.getRootItem();

            for (SyncItem item : items) {
                item.save(record, root);
            }
        } catch (Exception e) {
            log.error("Could not serialize SyncItems:", e);
            throw new HibernateException("Could not serialize SyncItems", e);
        }

        String newRecord = record.toStringAsDocumentFragment();

        //02/09/2008: replaced setClob() with setString() to deal with encoding issues: mysql Clob inexplicably truncates if
        // it encounters non-ASCII character
        //ps.setClob(index, Hibernate.createClob(record.toStringAsDocumentFragment()));
        ps.setString(index, newRecord);
    }
}