Example usage for java.sql Types BLOB

List of usage examples for java.sql Types BLOB

Introduction

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

Prototype

int BLOB

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

Click Source Link

Document

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

Usage

From source file:com.tesora.dve.db.NativeType.java

public boolean isBinaryType() {
    return dataType == Types.LONGVARBINARY || dataType == Types.BLOB || dataType == Types.BINARY
            || dataType == Types.VARBINARY;
}

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./* w ww .  jav a2 s  .  c  o m*/
 * @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:org.apache.openjpa.jdbc.sql.PostgresDictionary.java

/**
 * Handle XML and bytea/oid columns in a PostgreSQL way.
 *///from   ww  w .j  a  v  a 2s  .c om
@Override
public void setNull(PreparedStatement stmnt, int idx, int colType, Column col) throws SQLException {
    if (col != null && col.isXML()) {
        stmnt.setNull(idx, Types.OTHER);
        return;
    }

    // OPENJPA-308
    if (colType == Types.BLOB)
        colType = Types.BINARY;
    stmnt.setNull(idx, colType);
}

From source file:org.jumpmind.metl.core.runtime.component.Sorter.java

protected void createDatabase() {
    if (databasePlatform == null) {
        ResettableBasicDataSource ds = new ResettableBasicDataSource();
        ds.setDriverClassName(Driver.class.getName());
        ds.setMaxActive(1);//from w  w  w. j a va2s .c  o m
        ds.setInitialSize(1);
        ds.setMinIdle(1);
        ds.setMaxIdle(1);
        databaseName = UUID.randomUUID().toString();
        ds.setUrl("jdbc:h2:mem:" + databaseName);
        databasePlatform = JdbcDatabasePlatformFactory.createNewPlatformInstance(ds, new SqlTemplateSettings(),
                true, false);

        Model inputModel = context.getFlowStep().getComponent().getInputModel();
        List<ModelEntity> entities = inputModel.getModelEntities();
        for (ModelEntity entity : entities) {
            Table table = new Table();
            table.setName(entity.getName() + "_1");
            List<ModelAttribute> attributes = entity.getModelAttributes();
            for (ModelAttribute attribute : attributes) {
                DataType dataType = attribute.getDataType();
                Column column = new Column(attribute.getName());
                if (dataType.isNumeric()) {
                    column.setTypeCode(Types.DECIMAL);
                } else if (dataType.isBoolean()) {
                    column.setTypeCode(Types.BOOLEAN);
                } else if (dataType.isTimestamp()) {
                    column.setTypeCode(Types.TIMESTAMP);
                } else if (dataType.isBinary()) {
                    column.setTypeCode(Types.BLOB);
                } else {
                    column.setTypeCode(Types.LONGVARCHAR);
                }

                column.setPrimaryKey(attribute.isPk());
                table.addColumn(column);
            }

            alterCaseToMatchLogicalCase(table);
            databasePlatform.createTables(false, false, table);
        }

        log(LogLevel.INFO, "Creating databasePlatform with the following url: %s", ds.getUrl());
    }
}

From source file:nl.nn.adapterframework.util.JdbcUtil.java

public static boolean isBlobType(final ResultSet rs, final int colNum, final ResultSetMetaData rsmeta)
        throws SQLException {
    switch (rsmeta.getColumnType(colNum)) {
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
    case Types.BLOB:
        return true;
    default://  w ww.j a  va 2  s. co  m
        return false;
    }
}

From source file:org.fastcatsearch.datasource.reader.DBReader.java

private void fill() throws IRException {

    bulkCount = 0;//from  ww w.j ava2 s. co  m
    try {
        ResultSetMetaData rsMeta = null;
        //? Tmp ??? .
        deleteTmpLob();

        try {
            rsMeta = r.getMetaData();
        } catch (SQLException e) {
            return;
        }
        while (r.next()) {

            Map<String, Object> keyValueMap = new HashMap<String, Object>();

            for (int i = 0; i < columnCount; i++) {
                int columnIdx = i + 1;
                int type = rsMeta.getColumnType(columnIdx);

                String str = "";

                String lobType = null;
                if (type == Types.BLOB || type == Types.BINARY || type == Types.LONGVARBINARY
                        || type == Types.VARBINARY || type == Types.JAVA_OBJECT) {
                    lobType = LOB_BINARY;
                } else if (type == Types.CLOB || type == Types.NCLOB || type == Types.SQLXML
                        || type == Types.LONGVARCHAR || type == Types.LONGNVARCHAR) {
                    lobType = LOB_STRING;
                }

                if (lobType == null) {
                    str = r.getString(columnIdx);

                    if (str != null) {
                        keyValueMap.put(columnName[i], str);
                    } else {
                        //    ? ? ? NULL ? 
                        keyValueMap.put(columnName[i], "");
                    }
                } else {
                    File file = null;

                    if (lobType == LOB_BINARY) {
                        // logger.debug("Column-"+columnIdx+" is BLOB!");
                        // BLOB?   .
                        ByteArrayOutputStream buffer = null;
                        try {
                            if (!useBlobFile) {
                                buffer = new ByteArrayOutputStream();
                            }
                            file = readTmpBlob(i, columnIdx, rsMeta, buffer);
                            if (useBlobFile) {
                                keyValueMap.put(columnName[i], file);
                            } else {
                                keyValueMap.put(columnName[i], buffer.toByteArray());
                            }
                        } finally {
                            if (buffer != null) {
                                try {
                                    buffer.close();
                                } catch (IOException ignore) {
                                }
                            }
                        }
                    } else if (lobType == LOB_STRING) {
                        StringBuilder sb = null;
                        if (!useBlobFile) {
                            sb = new StringBuilder();
                        }
                        file = readTmpClob(i, columnIdx, rsMeta, sb);
                        if (useBlobFile) {
                            keyValueMap.put(columnName[i], file);
                        } else {
                            keyValueMap.put(columnName[i], sb.toString());
                        }
                    }

                    //?   ?? .
                    if (file != null) {
                        tmpFile.add(file);
                    }
                }
            }

            dataSet[bulkCount] = keyValueMap;
            bulkCount++;
            totalCnt++;

            if (bulkCount >= BULK_SIZE) {
                break;
            }
        }

    } catch (Exception e) {

        logger.debug("", e);

        try {
            if (r != null) {
                r.close();
            }
        } catch (SQLException ignore) {
        }

        try {
            if (pstmt != null) {
                pstmt.close();
            }
        } catch (SQLException ignore) {
        }

        try {
            if (con != null && !con.isClosed()) {
                con.close();
            }
        } catch (SQLException ignore) {
        }

        throw new IRException(e);
    }
}

From source file:org.easyrec.store.dao.core.impl.ProfileDAOMysqlImpl.java

@Override
public boolean deleteProfile(Integer tenantId, Integer itemId, Integer itemTypeId) {

    if (tenantId == null) {
        throw new IllegalArgumentException("tenantId must not be 'null'!");
    }//www  . j  ava  2s.c o m
    if (itemId == null) {
        throw new IllegalArgumentException("itemId must not be 'null'!");
    }
    if (itemTypeId == null) {
        throw new IllegalArgumentException("itemTypeId must not be 'null'");
    }

    String itemType = itemTypeDAO.getTypeById(tenantId, itemTypeId);

    String mappedItemId = idMappingDAO.lookup(itemId);
    if (mappedItemId == null)
        throw new IllegalArgumentException("itemId has no string equivalent");

    Object[] args = { tenantId, mappedItemId, itemType, null, null };

    int[] argTypes = { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.BLOB };

    PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory(STORE_PROFILE_QUERY,
            argTypes);

    int rowsAffected = getJdbcTemplate().update(factory.newPreparedStatementCreator(args));
    return (rowsAffected > 0);
}

From source file:com.apatar.webdav.WebDavNode.java

protected KeyInsensitiveMap createRecord(WebdavResource res, String url, String uri) {
    KeyInsensitiveMap datas = new KeyInsensitiveMap();

    if (res.isCollection()) {
        datas.put("isFolder", true);
        datas.put("String_Content", "");
        datas.put("Content", new JdbcObject(null, Types.BLOB));
    } else {/*  ww  w. j av  a 2s.  c  o  m*/
        datas.put("isFolder", false);
        try {

            if (0 < res.getGetContentLength()) {
                InputStream in = res.getMethodData();
                File f = File.createTempFile("apatar", ".tmp");

                listTmpFiles.add(f);

                FileOutputStream fout = new FileOutputStream(f);
                StringBuffer strBuff = new StringBuffer();

                int read = 0;
                while (-1 != read) {

                    if (!ApplicationData.ProcessingProgress.Status()) {
                        return null;
                    }

                    read = in.read();
                    fout.write(read);

                    if (strBuff.length() < 2000) {
                        strBuff.append((char) read);
                    }
                }
                fout.close();

                datas.put("Content", new FileInputStream(f));
                datas.put("String_Content", strBuff.toString());
                in.close();

            } else {
                datas.put("Content", new JdbcObject(null, Types.BLOB));
                datas.put("String_Content", "");
            }
        } catch (HttpException e) {
            ApplicationData.ProcessingProgress.Log(e);
            e.printStackTrace();
        } catch (IOException e) {
            ApplicationData.ProcessingProgress.Log(e);
            e.printStackTrace();
        }
    }

    String path = convertHttpToString(res.getHttpURL());
    path = path.replace(url, "");
    path = path.replace(uri, "");

    datas.put("Name", res.getDisplayName());
    datas.put("Path", path);
    datas.put("Size", res.getGetContentLength());
    datas.put("Modified", new Date(res.getGetLastModified()));
    datas.put("Read", true);
    datas.put("Write", !res.isLocked());

    ApplicationData.ProcessingProgress.Log("Downloading resource: " + convertHttpToString(res.getHttpURL()));

    return datas;
}

From source file:com.opensymphony.module.propertyset.database.JDBCPropertySet.java

private void setValues(PreparedStatement ps, int type, String key, Object value)
        throws SQLException, PropertyException {
    // Patched by Edson Richter for MS SQL Server JDBC Support!
    String driverName;/*from   w  w w. j a va2 s.c  o  m*/

    try {
        driverName = ps.getConnection().getMetaData().getDriverName().toUpperCase();
    } catch (Exception e) {
        driverName = "";
    }

    ps.setNull(1, Types.VARCHAR);
    ps.setNull(2, Types.TIMESTAMP);

    // Patched by Edson Richter for MS SQL Server JDBC Support!
    // Oracle support suggestion also Michael G. Slack
    if ((driverName.indexOf("SQLSERVER") >= 0) || (driverName.indexOf("ORACLE") >= 0)) {
        ps.setNull(3, Types.BINARY);
    } else {
        ps.setNull(3, Types.BLOB);
    }

    ps.setNull(4, Types.FLOAT);
    ps.setNull(5, Types.NUMERIC);
    ps.setInt(6, type);
    ps.setString(7, globalKey);
    ps.setString(8, key);

    switch (type) {
    case PropertySet.BOOLEAN:

        Boolean boolVal = (Boolean) value;
        ps.setInt(5, boolVal.booleanValue() ? 1 : 0);

        break;

    case PropertySet.DATA:

        Data data = (Data) value;
        ps.setBytes(3, data.getBytes());

        break;

    case PropertySet.DATE:

        Date date = (Date) value;
        ps.setTimestamp(2, new Timestamp(date.getTime()));

        break;

    case PropertySet.DOUBLE:

        Double d = (Double) value;
        ps.setDouble(4, d.doubleValue());

        break;

    case PropertySet.INT:

        Integer i = (Integer) value;
        ps.setInt(5, i.intValue());

        break;

    case PropertySet.LONG:

        Long l = (Long) value;
        ps.setLong(5, l.longValue());

        break;

    case PropertySet.STRING:
        ps.setString(1, (String) value);

        break;

    default:
        throw new PropertyException("This type isn't supported!");
    }
}

From source file:nl.nn.adapterframework.util.JdbcUtil.java

public static String getValue(final ResultSet rs, final int colNum, final ResultSetMetaData rsmeta,
        String blobCharset, boolean decompressBlobs, String nullValue, boolean trimSpaces, boolean getBlobSmart,
        boolean encodeBlobBase64) throws JdbcException, IOException, SQLException, JMSException {
    switch (rsmeta.getColumnType(colNum)) {
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
    case Types.BLOB:
        try {/*from www .ja  v  a2  s  .  c o  m*/
            return JdbcUtil.getBlobAsString(rs, colNum, blobCharset, false, decompressBlobs, getBlobSmart,
                    encodeBlobBase64);
        } catch (JdbcException e) {
            log.debug("Caught JdbcException, assuming no blob found", e);
            return nullValue;
        }
    case Types.CLOB:
        try {
            return JdbcUtil.getClobAsString(rs, colNum, false);
        } catch (JdbcException e) {
            log.debug("Caught JdbcException, assuming no clob found", e);
            return nullValue;
        }
        // return "undefined" for types that cannot be rendered to strings easily
    case Types.ARRAY:
    case Types.DISTINCT:
    case Types.BINARY:
    case Types.REF:
    case Types.STRUCT:
        return "undefined";
    default: {
        String value = rs.getString(colNum);
        if (value == null) {
            return nullValue;
        }
        if (trimSpaces) {
            return value.trim();
        }
        return value;
    }
    }
}