Example usage for java.sql Blob getClass

List of usage examples for java.sql Blob getClass

Introduction

In this page you can find the example usage for java.sql Blob getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.etudes.jforum.dao.oracle.OracleUtils.java

/**
 * The query should look like://from   w w  w. ja  v a 2s . c  om
 * 
 * SELECT blob_field from any_table WHERE id = ? FOR UPDATE
 * 
 * BUT KEEP IN MIND:
 * 
 * When you insert record in previous step, it should go with empty_blob() like:
 * 
 * INSERT INTO jforum_posts_text ( post_text ) VALUES (EMPTY_BLOB())
 * 
 * @param query
 * @param idForQuery
 * @param value
 * @throws IOException
 * @throws SQLException
 */
public static void writeBlobUTF16BinaryStream(String query, int idForQuery, String value)
        throws IOException, SQLException {
    PreparedStatement p = JForum.getConnection().prepareStatement(query);
    p.setInt(1, idForQuery);

    ResultSet rs = p.executeQuery();
    rs.next();
    Blob postText = rs.getBlob(1);

    //wipe out the Blob contents 
    postText.truncate(0);

    if (logger.isDebugEnabled())
        logger.debug("post test is a " + postText.getClass().getName());

    // OutputStream blobWriter = ((oracle.sql.BLOB)postText).setBinaryStream(0L);
    OutputStream blobWriter = postText.setBinaryStream(0L);
    blobWriter.write(value.getBytes("UTF-16"));

    blobWriter.flush();
    blobWriter.close();
    rs.close();
    p.close();
}

From source file:org.quartz.impl.jdbcjobstore.oracle.OracleDelegate.java

protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException {

    Blob blob = rs.getBlob(column); // get blob

    if (blob == null) {
        throw new SQLException("Driver's Blob representation is null!");
    }//from  ww  w.j  ava2  s  .  com

    if (blob instanceof oracle.sql.BLOB) { // is it an oracle blob?
        ((oracle.sql.BLOB) blob).putBytes(1, data);
        return blob;
    } else {
        throw new SQLException(
                "Driver's Blob representation is of an unsupported type: " + blob.getClass().getName());
    }
}

From source file:org.quartz.impl.jdbcjobstore.oracle.weblogic.WebLogicOracleDelegate.java

/**
 * Check for the Weblogic Blob wrapper, and handle accordingly...
 *//* w w w.  j  a  va 2s .  c o  m*/
protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException {
    Blob blob = rs.getBlob(column);

    if (blob == null) {
        throw new SQLException("Driver's Blob representation is null!");
    }

    // handle thin driver's blob
    if (blob instanceof weblogic.jdbc.vendor.oracle.OracleThinBlob) {
        ((weblogic.jdbc.vendor.oracle.OracleThinBlob) blob).putBytes(1, data);
        return blob;
    } else if (blob.getClass().getPackage().getName().startsWith("weblogic.")) {
        // (more slowly) handle blob for wrappers of other variations of drivers...
        try {
            // try to find putBytes method...
            Method m = blob.getClass().getMethod("putBytes", new Class[] { long.class, byte[].class });
            m.invoke(blob, new Object[] { new Long(1), data });
        } catch (Exception e) {
            try {
                // Added this logic to the original code from OpenSymphony
                // putBytes method does not exist. Try setBytes
                Method m = blob.getClass().getMethod("setBytes", new Class[] { long.class, byte[].class });
                m.invoke(blob, new Object[] { new Long(1), data });
            } catch (Exception e2) {
                throw new SQLException(
                        "Unable to find putBytes(long,byte[]) or setBytes(long,byte[]) methods on blob: " + e2);
            }
        }
        return blob;
    } else {
        return super.writeDataToBlob(rs, column, data);
    }
}