Package java.sql

Examples of java.sql.Blob


        if (useGetBytesForBlobs)
            return rs.getBytes(column);
        if (useGetObjectForBlobs)
            return (byte[]) rs.getObject(column);

        Blob blob = getBlob(rs, column);
        if (blob == null)
            return null;
        int length = (int) blob.length();
        if (length == 0)
            return null;
        return blob.getBytes(1, length);
    }
View Full Code Here


            setTimeouts(stmnt, store.getFetchConfiguration(), true);
            res = stmnt.executeQuery();
            if (!res.next()) {
                throw new InternalException(_loc.get("stream-exception"));
            }
            Blob blob = res.getBlob(1);
            OutputStream os = blob.setBinaryStream(1);
            copy(is, os);
            os.close();
            res.updateBlob(1, blob);
            res.updateRow();
View Full Code Here

            int colType = rs.getMetaData().getColumnType(1);

            switch(colType) {
                case Types.BLOB :
                    Blob blob = rs.getBlob(1);
                    return new JDBCInputStream(blob.getBinaryStream(), cnx);
                //break;

                case Types.CLOB :
                    Clob clob = rs.getClob(1);
                    return new JDBCInputStream(clob.getAsciiStream(), cnx);
View Full Code Here

            if (value instanceof JDBCxlobHelper) {
                statement.setBinaryStream(position, ((JDBCxlobHelper)value).inputStream, ((JDBCxlobHelper)value).length);
            } else if (value instanceof Source){
                statement.setBinaryStream(position, ((Source)value).getInputStream(), (int)((Source)value).getContentLength());
            } else {
                Blob blob = null;
                if (value instanceof Blob) {
                    blob = (Blob) value;
                } else if( value instanceof File) {
                    file = (File)value;
                    blob = new BlobHelper(new FileInputStream(file), (int) file.length());
View Full Code Here

            // that uses a Blob java-type for non-Blob types should be updated
            // to use the correct type.
            Object originalObject;
            byte[] fieldBytes;
            try {
                Blob theBlob = rs.getBlob(columnIndex);
                fieldBytes = toByteArray(theBlob);
                originalObject = theBlob;
            } catch (SQLException e) {
                // for backward compatibility if getBlob didn't work try getBytes
                fieldBytes = rs.getBytes(columnIndex);
View Full Code Here

                    break;
                case 12:
                    Object originalObject;
                    byte[] fieldBytes;
                    try {
                        Blob theBlob = rs.getBlob(ind);
                        fieldBytes = theBlob != null ? theBlob.getBytes(1, (int) theBlob.length()) : null;
                        originalObject = theBlob;
                    } catch (SQLException e) {
                        // for backward compatibility if getBlob didn't work try getBytes
                        fieldBytes = rs.getBytes(ind);
                        originalObject = fieldBytes;
View Full Code Here

                case 0: {o = rs.getObject(col); break;}
                case 1: {Array v=rs.getArray(col);o=v;break;}
                case 2: {InputStream v=rs.getAsciiStream(col);o=v;break;}
                case 3: {BigDecimal v=rs.getBigDecimal(col);o=v;break;}
                case 4: {InputStream v=rs.getBinaryStream(col);o=v;break;}
                case 5: {Blob v=rs.getBlob(col);o=v;break;}
                case 6: {boolean v=rs.getBoolean(col);o=new Boolean(v);break;}
                case 7: {byte v=rs.getByte(col);o=new Byte(v);break;}
                case 8: {byte[] v=rs.getBytes(col);o=v;break;}
                case 9: {Reader v=rs.getCharacterStream(col);o=v;break;}
                case 10:{Clob v=rs.getClob(col);o=v;break;}
                case 11:{Date v=rs.getDate(col);o=v; break;}
                case 12:{double v=rs.getDouble(col);o=new Double(v);break;}
                case 13:{float v=rs.getFloat(col);o=new Float(v);break;}
                case 14:{int v=rs.getInt(col);o=new Integer(v);break;}
                case 15:{long v=rs.getLong(col);o=new Long(v);break;}
                case 16:{Ref v=rs.getRef(col);o=v;break;}
                case 17:{short v=rs.getShort(col);o=new Short(v);break;}
                case 18:{String v=rs.getString(col);o=v;break;}
                case 19:{Time v=rs.getTime(col);o=v;break;}
                case 20:{Timestamp v=rs.getTimestamp(col);o=v;break;}
//        case 21:{URL v=rs.getURL(col);o=v;break;}
                default: return null;
            }
            // fixup if it contains classname (remove "random" part after @)
            String v = o.toString();
            if (v.indexOf('@') != -1) { // non standard java object.
                s += "Object'   \t: "+prettyType(o);
            } else {
                // default stringifier...
                s += "'"+v+"'    \t: "+o.getClass().getName();
            }
View Full Code Here

        if (value == null) {
            return null;
        }
        if (value instanceof Blob) {
            try {
                Blob valueBlob = (Blob) value;
                return valueBlob.getBytes(1, (int) valueBlob.length());
            } catch (SQLException e) {
                String errMsg = "Error getting byte[] from Blob: " + e.toString();
                Debug.logError(e, errMsg, module);
                return null;
            }
View Full Code Here

            testValue.store();
            testValue = delegator.findOne("TestFieldType", UtilMisc.toMap("testFieldTypeId", id), false);
            assertEquals("testFieldTypeId", id, testValue.get("testFieldTypeId"));
            byte[] c = null;
            try {
                Blob blob = (Blob) testValue.get("blobField");
                c = blob.getBytes(1, (int) blob.length());
            } catch (ClassCastException e) {
                c = (byte[]) testValue.get("blobField");
            }
            assertEquals("Byte array read from entity is the same length", b.length, c.length);
            for (int i = 0; i < b.length; i++) {
View Full Code Here

        // At this point we don't have any idea if the DB2 column was defined as
        //     a blob or if it was defined as CHAR for BIT DATA.
        // First try as a blob, if that doesn't work, then try as CHAR for BIT DATA
        // If that doesn't work, then go ahead and throw the first exception
        try {
            Blob blob = getBlob(rs, column);
            if (blob == null) {
                return null;
            }
           
            int length = (int) blob.length();
            if (length == 0) {
                return null;
            }
           
            return blob.getBytes(1, length);
        }
        catch (SQLException e) {
            try {
                return rs.getBytes(column);
            }
View Full Code Here

TOP

Related Classes of java.sql.Blob

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.