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.executequery.gui.resultset.TableCellData.java

public boolean isClob() {

    return (dataType == Types.CLOB || dataType == Types.LONGVARCHAR);
}

From source file:au.com.ish.derbydump.derbydump.metadata.Column.java

/**
 * Get a string value for the value in this column in the datarow
 * /*from   w  ww .ja v a2s .c  om*/
 * @param dataRow The row which we are exporting
 * @return an SQL statement compliant string version of the value
 */
public String toString(ResultSet dataRow) throws SQLException {

    switch (getColumnDataType()) {
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB: {
        Blob obj = dataRow.getBlob(columnName);
        return (obj == null) ? "NULL" : processBinaryData(obj);
    }

    case Types.CLOB: {
        Clob obj = dataRow.getClob(columnName);
        return (obj == null) ? "NULL" : processClobData(obj);
    }

    case Types.CHAR:
    case Types.LONGNVARCHAR:
    case Types.VARCHAR: {
        String obj = dataRow.getString(columnName);
        return (obj == null) ? "NULL" : processStringData(obj);
    }

    case Types.TIME: {
        Time obj = dataRow.getTime(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.DATE: {
        Date obj = dataRow.getDate(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.TIMESTAMP: {
        Timestamp obj = dataRow.getTimestamp(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.SMALLINT: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.BIGINT: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.INTEGER: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.NUMERIC:
    case Types.DECIMAL: {
        BigDecimal obj = dataRow.getBigDecimal(columnName);
        return (obj == null) ? "NULL" : String.valueOf(obj);
    }

    case Types.REAL:
    case Types.FLOAT: {
        Float obj = dataRow.getFloat(columnName);
        // dataRow.getFloat() always returns a value. only way to check the null is wasNull() method
        return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj);
    }

    case Types.DOUBLE: {
        Double obj = dataRow.getDouble(columnName);
        return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj);
    }

    default: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }
    }
}

From source file:org.jumpmind.db.platform.derby.DerbyDatabasePlatform.java

@Override
public boolean isClob(int type) {
    return type == Types.CLOB;
}

From source file:com.trackplus.ddl.GenericStringValueConverter.java

protected String extractColumnValue(ResultSet resultSet, int columnIdx, int jdbcType)
        throws SQLException, DDLException {
    String value = resultSet.getString(columnIdx);
    if (value != null) {
        switch (jdbcType) {
        case Types.NUMERIC:
        case Types.DECIMAL:
            break;
        case Types.BIT:
        case Types.BOOLEAN:
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
        case Types.REAL:
        case Types.FLOAT:
        case Types.DOUBLE: {
            break;
        }/*  w  w  w.j  a  va2 s.com*/

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.TIME:
        case Types.CLOB:
        case Types.ARRAY:
        case Types.REF: {
            value = "'" + value.replaceAll("'", "''") + "'";
            break;
        }
        case Types.DATE:
        case Types.TIMESTAMP: {
            Date d = resultSet.getDate(columnIdx);
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            int year = cal.get(Calendar.YEAR);
            if (year < 1900) {
                throw new DDLException("Invalid date:" + d);
            } else {
                value = "'" + value + "'";
            }
            break;
        }
        case Types.BLOB:
        case Types.LONGVARBINARY: {
            Blob blobValue = resultSet.getBlob(columnIdx);
            String str = new String(Base64.encodeBase64(blobValue.getBytes(1l, (int) blobValue.length())));
            value = "'" + str + "'";
            break;
        }
        default:
            break;
        }
    }
    return value;
}

From source file:com.adaptris.core.services.jdbc.types.ClobColumnTranslatorTest.java

@Test
public void testClobIncorrectTypeColumnName() throws Exception {
    JdbcResultRow row = new JdbcResultRow();
    row.setFieldValue("testField", new Integer(999), Types.CLOB);

    try {/*ww w  . j ava2s .c  o m*/
        translator.translate(row, "testField");
        fail();
    } catch (Exception ex) {
        // pass, expected
    }
}

From source file:org.ojbc.util.camel.processor.audit.SQLLoggingProcessor.java

private void writeLogInfoToDatabase(LogInfo logInfo) {

    String sql = "insert into AuditLog (origin,destination,replyTo,messageID,federationID,employerName,employerSubUnitName,userLastName,userFirstName,"
            + "identityProviderID,hostAddress,camelContextID,osgiBundleName,osgiBundleVersion,osgiBundleDescription,soapMessage) "
            + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

    int[] types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
            Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
            Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.CLOB };

    Object[] values = new Object[] { logInfo.origin, logInfo.destination, logInfo.replyTo, logInfo.messageId,
            logInfo.federationId, logInfo.employerName, logInfo.employerSubUnitName, logInfo.userLastName,
            logInfo.userFirstName, logInfo.idp, logInfo.hostAddress, logInfo.camelContextId, logInfo.bundleName,
            logInfo.bundleVersion, logInfo.bundleBundleName, logInfo.soapMessage };

    jdbcTemplate.update(sql, values, types);

}

From source file:org.jumpmind.symmetric.android.AndroidSqlTemplate.java

@Override
public String queryForClob(String sql, Object... args) {
    return queryForClob(sql, Types.CLOB, TypeMap.CLOB, args);
}

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

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type.spec) {
    case STRING://from   w w  w.  j  a va2s.  c  o  m
        if (type.isUnconstrained()) {
            return jdbcInfo("VARCHAR(255)", Types.VARCHAR);
        } else if (type.isClob() || type.length > 2000) {
            return jdbcInfo("CLOB", Types.CLOB);
        } else {
            return jdbcInfo("VARCHAR(%d)", type.length, Types.VARCHAR);
        }
    case BOOLEAN:
        return jdbcInfo("SMALLINT", Types.BIT);
    case LONG:
        return jdbcInfo("BIGINT", Types.BIGINT);
    case DOUBLE:
        return jdbcInfo("DOUBLE", Types.DOUBLE);
    case TIMESTAMP:
        return jdbcInfo("TIMESTAMP", Types.TIMESTAMP);
    case BLOBID:
        return jdbcInfo("VARCHAR(40)", Types.VARCHAR);
    // -----
    case NODEID:
    case NODEIDFK:
    case NODEIDFKNP:
    case NODEIDFKMUL:
    case NODEIDFKNULL:
    case NODEIDPK:
    case NODEVAL:
        return jdbcInfo("VARCHAR(36)", Types.VARCHAR);
    case SYSNAME:
    case SYSNAMEARRAY:
        return jdbcInfo("VARCHAR(250)", Types.VARCHAR);
    case TINYINT:
        return jdbcInfo("SMALLINT", Types.TINYINT);
    case INTEGER:
        return jdbcInfo("INTEGER", Types.INTEGER);
    case AUTOINC:
        return jdbcInfo("INTEGER", Types.INTEGER); // TODO
    case FTINDEXED:
        return jdbcInfo("CLOB", Types.CLOB);
    case FTSTORED:
        return jdbcInfo("CLOB", Types.CLOB);
    case CLUSTERNODE:
        return jdbcInfo("VARCHAR(25)", Types.VARCHAR);
    case CLUSTERFRAGS:
        return jdbcInfo("VARCHAR(4000)", Types.VARCHAR);
    default:
        throw new AssertionError(type);
    }
}

From source file:ro.nextreports.designer.querybuilder.ResultSetTableModel.java

protected boolean isClobColumn(int column) {
    return result.getColumnType(column) == Types.CLOB;
}

From source file:RowSetModel.java

public Class getColumnClass(int column) {
    String cname;/*from   w  w  w. jav a2 s  . co  m*/
    int type;

    try {
        ResultSetMetaData meta = rowSet.getMetaData();

        if (meta == null) {
            return null;
        }
        type = meta.getColumnType(column + 1);
    } catch (SQLException e) {
        e.printStackTrace();
        return super.getColumnClass(column);
    }
    switch (type) {
    case Types.BIT: {
        cname = "java.lang.Boolean";
        break;
    }
    case Types.TINYINT: {
        cname = "java.lang.Byte";
        break;
    }
    case Types.SMALLINT: {
        cname = "java.lang.Short";
        break;
    }
    case Types.INTEGER: {
        cname = "java.lang.Integer";
        break;
    }
    case Types.BIGINT: {
        cname = "java.lang.Long";
        break;
    }
    case Types.FLOAT:
    case Types.REAL: {
        cname = "java.lang.Float";
        break;
    }
    case Types.DOUBLE: {
        cname = "java.lang.Double";
        break;
    }
    case Types.NUMERIC: {
        cname = "java.lang.Number";
        break;
    }
    case Types.DECIMAL: {
        cname = "java.math.BigDecimal";
        break;
    }
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR: {
        cname = "java.lang.String";
        break;
    }
    case Types.DATE: {
        cname = "java.sql.Date";
        break;
    }
    case Types.TIME: {
        cname = "java.sql.Time";
        break;
    }
    case Types.TIMESTAMP: {
        cname = "java.sql.Timestamp";
        break;
    }
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY: {
        cname = "byte[]";
        break;
    }
    case Types.OTHER:
    case Types.JAVA_OBJECT: {
        cname = "java.lang.Object";
        break;
    }
    case Types.CLOB: {
        cname = "java.sql.Clob";
        break;
    }
    case Types.BLOB: {
        cname = "java.ssql.Blob";
        break;
    }
    case Types.REF: {
        cname = "java.sql.Ref";
        break;
    }
    case Types.STRUCT: {
        cname = "java.sql.Struct";
        break;
    }
    default: {
        return super.getColumnClass(column);
    }
    }
    try {
        return Class.forName(cname);
    } catch (Exception e) {
        e.printStackTrace();
        return super.getColumnClass(column);
    }
}