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.pentaho.platform.repository.hibernate.usertypes.BlobtoByteArrayUserType.java

public Object nullSafeGet(final ResultSet arg0, final String[] arg1, final Object arg2)
        throws HibernateException, SQLException {

    Blob blob = arg0.getBlob(arg1[0]);
    if (blob != null) {
        byte[] bytes = blob.getBytes(1, (int) blob.length());
        return bytes;
    }//w  w w .  ja  v a  2  s  .c o  m
    return null;
}

From source file:org.ambraproject.hibernate.OTMBlobType.java

public Object nullSafeGet(ResultSet resultSet, String[] names, Object o)
        throws HibernateException, SQLException {
    java.sql.Blob sBlob = resultSet.getBlob(names[0]);

    if (!resultSet.wasNull()) {
        try {// w  w  w  .  j a  va  2s  .c o  m
            return newBlob(names[0], sBlob);
        } catch (Exception ex) {
            throw new HibernateException(ex.getMessage(), ex);
        }
    }

    return null;
}

From source file:com.wabacus.config.database.type.DB2.java

public byte[] getBlobValue(ResultSet rs, int iindex) throws SQLException {
    Blob blob = (Blob) rs.getBlob(iindex);
    if (blob == null)
        return null;
    BufferedInputStream bin = null;
    try {//from  w w w  .j  av  a 2 s .  c  o  m
        bin = new BufferedInputStream(blob.getInputStream());
        return Tools.getBytesArrayFromInputStream(bin);
    } catch (Exception e) {
        log.error("?", e);
        return null;
    } finally {
        if (bin != null) {
            try {
                bin.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:org.unitime.commons.hibernate.blob.XmlBlobType.java

public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws SQLException {
    Blob blob = rs.getBlob(names[0]);
    if (blob == null)
        return null;
    try {//from   w  w w  .  j  a va 2 s .  co m
        SAXReader reader = new SAXReader();
        GZIPInputStream gzipInput = new GZIPInputStream(blob.getBinaryStream());
        Document document = reader.read(gzipInput);
        gzipInput.close();
        return document;
    } catch (IOException e) {
        throw new HibernateException(e.getMessage(), e);
    } catch (DocumentException e) {
        throw new HibernateException(e.getMessage(), e);
    }
}

From source file:org.ralasafe.entitle.BackupManagerImpl.java

public void exportBackup(int id, OutputStream out) {
    Connection conn = null;//from  w  w w.  j a  v a 2  s  .  co  m
    PreparedStatement pstmt = null;
    try {
        conn = DBPower.getConnection(table.getId());
        conn.setAutoCommit(false);
        pstmt = conn.prepareStatement(SELECT_CONTENT_SQL);
        pstmt.setInt(1, id);
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            Blob blob = rs.getBlob(1);
            InputStream in = blob.getBinaryStream();
            byte[] buf = new byte[1024];
            int len = 0;
            while ((len = in.read(buf)) != -1) {
                out.write(buf, 0, len);
            }
            in.close();
        }
        conn.commit();
    } catch (Exception e) {
        log.error("", e);
    } finally {
        DBUtil.close(pstmt, conn);
    }
}

From source file:com.wabacus.config.database.type.DB2.java

public byte[] getBlobValue(ResultSet rs, String column) throws SQLException {
    Blob blob = (Blob) rs.getBlob(column);
    if (blob == null)
        return null;
    BufferedInputStream bin = null;
    try {//from   ww  w . java2 s  .  co m
        bin = new BufferedInputStream(blob.getInputStream());
        return Tools.getBytesArrayFromInputStream(bin);
    } catch (Exception e) {
        log.error("?" + column + "", e);
        return null;
    } finally {
        if (bin != null) {
            try {
                bin.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

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

public static InputStream getBlobInputStream(ResultSet rs, String columnName)
        throws SQLException, JdbcException {
    return getBlobInputStream(rs.getBlob(columnName), columnName);
}

From source file:org.killbill.billing.plugin.meter.timeline.shutdown.StartTimesMapper.java

@Override
public StartTimes map(final int index, final ResultSet r, final StatementContext ctx) throws SQLException {
    try {/*  ww w.  j a v  a2  s  .c  o  m*/
        return new StartTimes(DateTimeUtils.dateTimeFromUnixSeconds(r.getInt("time_inserted")),
                (Map<Integer, Map<Integer, DateTime>>) mapper.readValue(
                        r.getBlob("start_times").getBinaryStream(),
                        new TypeReference<Map<Integer, Map<Integer, DateTime>>>() {
                        }));
    } catch (IOException e) {
        throw new IllegalStateException(String.format("Could not decode the StartTimes map"), e);
    }
}

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

public static InputStream getBlobInputStream(ResultSet rs, int columnIndex, boolean blobIsCompressed)
        throws SQLException, JdbcException {
    return getBlobInputStream(rs.getBlob(columnIndex), columnIndex + "", blobIsCompressed);
}

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

public static InputStream getBlobInputStream(ResultSet rs, String columnName, boolean blobIsCompressed)
        throws SQLException, JdbcException {
    return getBlobInputStream(rs.getBlob(columnName), columnName, blobIsCompressed);
}