Example usage for java.sql ResultSet getBlob

List of usage examples for java.sql ResultSet getBlob

Introduction

In this page you can find the example usage for java.sql ResultSet getBlob.

Prototype

Blob getBlob(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a Blob object in the Java programming language.

Usage

From source file:org.sakaiproject.content.impl.serialize.impl.conversion.Type1BlobResourcesConversionHandler.java

public Object getValidateSource(String id, ResultSet rs) throws SQLException {
    ResultSetMetaData metadata = rs.getMetaData();
    byte[] rv = null;
    switch (metadata.getColumnType(1)) {
    case Types.BLOB:
        Blob blob = rs.getBlob(1);
        if (blob != null) {
            //System.out.println("getValidateSource(" + id + ") blob == " + blob + " blob.length == " + blob.length());
            rv = blob.getBytes(1L, (int) blob.length());
        } else {// w w w.j  av  a  2s.  co  m
            System.out.println("getValidateSource(" + id + ") blob is null");
        }
        break;
    case Types.CLOB:
        Clob clob = rs.getClob(1);
        if (clob != null) {
            rv = clob.getSubString(1L, (int) clob.length()).getBytes();
        }
        break;
    case Types.CHAR:
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
        rv = rs.getString(1).getBytes();
        break;
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        rv = rs.getBytes(1);
        break;
    }
    // System.out.println("getValidateSource(" + id + ") \n" + rv + "\n");
    return rv;

    //return rs.getBytes(1);
}

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

public static void streamBlob(final ResultSet rs, int columnIndex, String charset, boolean blobIsCompressed,
        String blobBase64Direction, Object target, boolean close)
        throws JdbcException, SQLException, IOException {
    streamBlob(rs.getBlob(columnIndex), columnIndex + "", charset, blobIsCompressed, blobBase64Direction,
            target, close);//from   w ww  .  j  ava 2 s. c  om
}

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

public static void streamBlob(final ResultSet rs, String columnName, String charset, boolean blobIsCompressed,
        String blobBase64Direction, Object target, boolean close)
        throws JdbcException, SQLException, IOException {
    streamBlob(rs.getBlob(columnName), columnName, charset, blobIsCompressed, blobBase64Direction, target,
            close);/*from   ww  w  .  j ava  2 s  .  c  o  m*/
}

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

public static String getBlobAsString(final ResultSet rs, int columnIndex, String charset, boolean xmlEncode,
        boolean blobIsCompressed, boolean blobSmartGet, boolean encodeBlobBase64)
        throws IOException, JdbcException, SQLException, JMSException {
    return getBlobAsString(rs.getBlob(columnIndex), columnIndex + "", charset, xmlEncode, blobIsCompressed,
            blobSmartGet, encodeBlobBase64);
}

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

public static String getBlobAsString(final ResultSet rs, String columnName, String charset, boolean xmlEncode,
        boolean blobIsCompressed, boolean blobSmartGet, boolean encodeBlobBase64)
        throws IOException, JdbcException, SQLException, JMSException {
    return getBlobAsString(rs.getBlob(columnName), columnName, charset, xmlEncode, blobIsCompressed,
            blobSmartGet, encodeBlobBase64);
}

From source file:com.surveypanel.dao.FormRowHandler.java

public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
    FormDTO formDTO = new FormDTO();
    formDTO.setId(rs.getString("id"));
    formDTO.setSurveyId(rs.getLong("surveyId"));
    formDTO.setQualified(rs.getBoolean("qualified"));
    formDTO.setFinish(rs.getBoolean("finish"));
    formDTO.setUpdated(rs.getDate("updated"));
    formDTO.setCreated(rs.getDate("created"));
    formDTO.setVariables(StateRowMapper.getMap(rs.getBlob("js_data")));
    formDTO.setXmlContent(rs.getString("xml_data"));
    return formDTO;
}

From source file:modelo.ProcesoVertimientosManagers.InformeProcesoSeco.java

public ArchivoExtension getArchivosCargado(int codigoProceso, Integer codigoArchivo) throws SQLException {

        SeleccionarArchivosInformesCargados select = new SeleccionarArchivosInformesCargados();
        ResultSet rset = select.getArchivosCargados(codigoProceso, codigoArchivo);

        String nombreArchivo = null;
        Blob dataArchivo = null;//from  w  w  w. j a v a2 s  .  c o  m
        ArchivoExtension archivo;

        while (rset.next()) {
            nombreArchivo = rset.getString("NOMBRE_ARCHIVO");
            dataArchivo = rset.getBlob("ARCHIVO");
        }

        archivo = new ArchivoExtension(dataArchivo, nombreArchivo);

        return archivo;
    }

From source file:edu.clemson.cs.nestbed.server.adaptation.sql.ProgramMessageSymbolSqlAdapter.java

private final ProgramMessageSymbol getProgramMessageSymbol(ResultSet resultSet) throws SQLException {
    int id = resultSet.getInt(Index.ID.index());
    int programID = resultSet.getInt(Index.PROGRAMID.index());
    String name = resultSet.getString(Index.NAME.index());
    Blob bytecodeBlob = resultSet.getBlob(Index.BYTECODE.index());
    Date timestamp = resultSet.getDate(Index.TIMESTAMP.index());

    byte[] bytecode = bytecodeBlob.getBytes(1, (int) bytecodeBlob.length());

    return new ProgramMessageSymbol(id, programID, name, bytecode, timestamp);
}

From source file:modelo.ProcesoVertimientosManagers.ManejoLodos.java

public ArchivoExtension getAnexoLodos(int codigoArchivo) throws SQLException {

    SeleccionarLodos select = new SeleccionarLodos();
    ResultSet rset = select.getAnexoLodos(codigoArchivo);

    String nombreArchivo = null;/* w w w .j a va  2  s.co m*/
    Blob dataArchivo = null;

    while (rset.next()) {
        nombreArchivo = rset.getString("NOMBRE_ARCHIVO");
        dataArchivo = rset.getBlob("ARCHIVO");
    }

    return new ArchivoExtension(dataArchivo, nombreArchivo);
}

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  .  j ava2 s.c  o m*/
 * @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();
    }
    }
}