Blob setBytes and setBinaryStream Clarification Needed

I'm writing a JDBC driver for SQL Server and working on the Blob implementation details.
One thing that is not clear in the JDBC spec to me at least is the behavior of the call to setBytes and to setBinaryStream on a Blob.
Say for a simple example I have a Blob with 5 bytes in it ->
1 2 3 4 5
AA BB CC DD EE
So in the database these 5 bytes are stored. I open a Blob on this field.
Then I call setBytes with offset of 3 and write bytes 11 22 33 44
Do I get this ->
1 2 3 4 5 6
AA BB 11 22 33 44 <- Writes over data, also past end of Blob.
Or this?
1 2 3 4 5
AA BB 11 22 33 <- Writes over data, but not past end of Blob.
Or this?
1 2 3 4 5 6 7 8 9
AA BB 11 22 33 44 CC DD EE <- Inserts data at offset, pushes existing data to right.
So in other words, does setBytes insert data at the insertion point, or start overwriting data at the insertion point? Also, does it allow you to keep writing the data in the backend Blob past the end of the Blob?
Same goes for setBinaryStream. The API spec is not clear about the desired behavior.
Thanks for any clues!
Matt

Well... looking at the API...
public void setBytes(int parameterIndex, byte[] x)
    throws SQLExceptionSets the designated parameter to the given Java array of bytes.
The driver converts this to an SQL VARBINARY or LONGVARBINARY
(depending on the argument's size relative to the driver's limits
on VARBINARY values) when it sends it to the database.
public void setBinaryStream(int parameterIndex, InputStream x,int length)
    throws SQLExceptionSets the designated parameter to the given input stream, which will
have the specified number of bytes. When a very large binary value
is input to a LONGVARBINARY parameter, it may be more practical to send
it via a java.io.InputStream object. The data will be read from the
stream as needed until end-of-file is reached.
It appears that setBytes() you pass in an entire in-memory array
of bytes, whereas setBinaryStream() allows you to pass in an
InputStream that contains the bytes.

Similar Messages

  • When to use setBytes() and setBinaryStream()

    Hi,
    I am using oracle thin driver to insert a image (blob type) into database.
    Which method of PreparedStatement interface should I use to insert data,
    setBytes() or SetBinaryStream().
    My understanding is BinaryStream also sends data in form of bytes.
    Then what is the difference between these two method ?
    Please let me know.
    Thanks,
    -Amol

    Well... looking at the API...
    public void setBytes(int parameterIndex, byte[] x)
        throws SQLExceptionSets the designated parameter to the given Java array of bytes.
    The driver converts this to an SQL VARBINARY or LONGVARBINARY
    (depending on the argument's size relative to the driver's limits
    on VARBINARY values) when it sends it to the database.
    public void setBinaryStream(int parameterIndex, InputStream x,int length)
        throws SQLExceptionSets the designated parameter to the given input stream, which will
    have the specified number of bytes. When a very large binary value
    is input to a LONGVARBINARY parameter, it may be more practical to send
    it via a java.io.InputStream object. The data will be read from the
    stream as needed until end-of-file is reached.
    It appears that setBytes() you pass in an entire in-memory array
    of bytes, whereas setBinaryStream() allows you to pass in an
    InputStream that contains the bytes.

  • Source and destination clarification needed

    Hi Guys,
    We are using SRM as an add-on component to ECC 6.0. We are on SRM Server 5.5. In the defination of backend system SAP asked us to create 4 entries.
    1. ONECLNTERP : RFC tick is on
    2. ONECLNTEBP:
    3. ONECLNTSUS:
    4. XXXCLNTYYY: Local tick is on.
    So this means 'ONECLNTERP' is my backend system i.e. ECC 6.0 and 'XXXCLNTYYY' is my local system.
    Now while defining backend system for Product category there is one 'Source System and there is 'Target system'. Source System: System from which master data is replicated. So this should be my SRM system (as Product category is a part of SRM) or this should be ECC (as My product categories are copy of material group from ECC).
    Target system is the system into which follow-on document of SC is transfered i.e. Backend ECC system.
    Am I correct to say the above. I'm confused about which system is source and which system is destination.
    While defining the Account Assignement category and defining the PR document type I'm facing the same problem as I've to define the source system.
    Can anybody clarify me??
    Thanks
    Debashish

    Hello Deb,
    I have not worked on ECC 6.0.
    But logically speaking the
    source system - has to be yr ECC as SRM would be taking the ref of matl masters from there only
    Target system - would be yr same ECC again if you are using only one backend (and I think you are)
    (if you are using multiple backend and you want followon document in diff backend then here the SID of that backend would come)
    BR
    Dinesh

  • Oracle.sql.BLOB.setBytes() Error

    Hi,
    I'm trying to use Java to put a large array of bytes into a BLOB table column. I'm first inserting the new row with an empty_blob() and then calling select <blob_column> ... for update and getting the oracle.sql.BLOB out of the resultset. I then try to call setBytes() on this BLOB and I get the following exception:
    java.sql.SQLException: Invalid argument(s) in call: putBytes()
    at oracle.jdbc.driver.T4CConnection.putBytes(T4CConnection.java:2440)
    at oracle.sql.BLOB.setBytes(BLOB.java:916)
    I'm using Oracle XE (oracle-xe-11.2.0-1.0.x86_64.rpm), the latest ojdbc6.jar, and jboss 4.2.2 on CentOS.
    A code snippet of what I'm doing:
    ... stmt = con.prepareStatement("select blob_column from blob_table where id=? for update"); stmt.setLong(1, Id); ResultSet rs = stmt.executeQuery(); try {     if (rs.next()) {         WrappedResultSet wrappedRs = (WrappedResultSet)rs;         BLOB oracleBlob = ((OracleResultSet)wrappedRs.getUnderlyingResultSet()).getBLOB(1);         if(oracleBlob != null) {             byte[] bytes = getData();             int pos = 0;             long bytesLeft = bytes.length;             log.debug("Attempting to write " + bytes.length + " bytes to BLOB");             while(bytesLeft > 0) {                 int bytesWritten = oracleBlob.setBytes(pos, bytes, pos, MAXBUFSIZE);                 log.debug("Wrote " + bytesWritten + " bytes to BLOB");                 bytesLeft -= bytesWritten;                 pos += bytesWritten;             }         }     } } finally {     rs.close(); } ...
    Any help would be greatly appreciated!

    Welcome to the forum!
    Thanks for posting the code and the DB, JDBC and app server versions. Those are what is needed to help.
    >
    java.sql.SQLException: Invalid argument(s) in call: putBytes()
                while(bytesLeft > 0) {
                    int bytesWritten = oracleBlob.setBytes(pos, bytes, pos, MAXBUFSIZE);
                    log.debug("Wrote " + bytesWritten + " bytes to BLOB");
                    bytesLeft -= bytesWritten;
                    pos += bytesWritten;That 'Invalid argument . . .' was your clue to look at the ARGUMENT values you are passing to the method call. You could have easily done that by displaying the values to the console each time in the loop BEFORE the method call.
    This is the signature of that method in the Javadocs (edited to highlight the relevant parts):
    http://docs.oracle.com/javase/6/docs/api/java/sql/Blob.html#setBytes(long, byte[])
    >
    int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException
    Writing starts at position pos in the BLOB value; len bytes from the given byte array are written.
    Parameters:
    pos - the position in the BLOB object at which to start writing; the first position is 1
    bytes - the array of bytes to be written to this BLOB object
    offset - the offset into the array bytes at which to start reading the bytes to be set
    len - the number of bytes to be written to the BLOB value from the array of bytes bytes
    >
    This is what you are passing for 'len': MAXBUFSIZE
    Most likely that value is LARGER than the 'byte array' that you are using; perhaps it is even the MAX int size.
    That value is invalid.
    In addition each time thru the loop you increment 'pos' and use 'pos' as the 'offset' into your array. Then you once again use MAXBUFSIZE as the number of bytes to write from your array. Even if MAXBUFSIZE is less than the length of your array at some point it will likely be greater than what is left of the array.
    For example, if MAXBUFSIZE is 2 and your array length is 3 the first 'put' will put the first two bytes. Then the second put will use a 'pos' of 2 and try to put 2 more bytes; except there is only one byte left.
    Your code updates the entire BLOB value. Best practices are to use the stream methods for reading and writing BLOB/CLOB rather than the 'setBytes' method you are using. The main reason for this is performance: the stream methods write DIRECTLY to the database.
    >
    Notes:
    The stream write methods described in this section write directly to the database when you write to the output stream. You do not need to run an UPDATE to write the data. However, you need to call close or flush to ensure all changes are written. CLOBs and BLOBs are transaction controlled. After writing to either, you must commit the transaction for the changes to be permanent.
    >
    See 'Reading and Writing BLOB and CLOB Data' in the JDBC Dev Guide
    http://docs.oracle.com/cd/B19306_01/java.102/b14355/oralob.htm#i1058044
    >
    Example: Writing BLOB Data
    Use the setBinaryOutputStream method of an oracle.sql.BLOB object to write BLOB data.
    The following example reads a vector of data into a byte array, then uses the setBinaryOutputStream method to write an array of character data to a BLOB.
    java.io.OutputStream outstream;
    // read data into a byte array
    byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    // write the array of binary data to a BLOB
    outstream = ((BLOB)my_blob).setBinaryOutputStream(1L);
    outstream.write(data);

  • Java.lang.AbstractMethodError: oracle.sql.BLOB.setBytes

    Hi ,
    When I deployed an application ( In Oracle 10g )that uses oracleresultset i am getting an error as follows java.lang.AbstractMethodError: oracle.sql.BLOB.setBytes
    anybody has a clue ?
    Vishnu

    Hi Vishnu,
    I got the same error, and also when trying blob.setBinaryStream(1L);
    By me the DB is an 8.1.6 and the JDBC Driver I tried are both the new 10.1 and older ones.
    Did you solve your problem ? In which case I would be interested in a solution. A work around seems to be the blob.getBinaryOutputStream() method, but this is a problem for me since it is not portable.
    Regards
    Michele

  • Since applying Feb 2013 Sharepoint 2010 CUs - Critical event log entries for Blob cache and missing images

    Hi,
    Since applying the February 2013 SharePoint 2010 updates, we are getting lots of entries in our event logs along the following:
    Content Management     Publishing Cache         
    5538     Critical 
    An error occurred in the blob cache.  The exception message was 'The system cannot find the file specified. (Exception from HRESULT: 0x80070002)’
    In pretty much all of these cases the image/ file in question that is reported in the ULS logs as missing is not actually in the collaboration site, master page / html etc so the fix needs to go back to the site owner to make the correction to avoid
    the 404 (if they make it!). This has only started happening, I believe since feb 2013 sp2010 cumulative updates updates
    I didn’t see this mentioned as a change / in the Fix list of the February updates. i.e. it flags up a critical error in our event logs. So with a lot of sites and a lot of missing images your event log can quickly fill up.
    Obviously you can suppress them in the monitoring -> web content management ->publishing cache = none & none which is not ideal.
    So my question is... are others seeing this and was a change made by Microsoft to flag a 404 missing image / file up a critical error in event log when blob cache is enabled?
    If i log this with MS they will just say, you need to fix it up the missing files in the site but would be nice to know this had changed prior! I also deleted and recreated the blob cache and this made no diffference
    thanks
    Brad

    I'm facing the same error on our SharePoint 2013 farm. We are on Aug 2013 CU and if the Dec CU (which is supposed to be the latest) doesn't solve it then what else could be done.
    Some users started getting the message "Server is busy now try again later" with a corelation id. I looked up ULS with that corelation id and found these two errors in addition to hundreds of "Micro Trace Tags (none)" and "forced
    due to logging gap":
    "GetFileFromUrl: FileNotFoundException when attempting get file Url /favicon.ico The system cannot find the file specified. (Exception from HRESULT: 0x80070002)"
    "Error in blob cache. System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)"
    "Unable to cache URL /FAVICON.ICO.  File was not found" 
    Looks like this is a bug and MS hasn't fixed it in Dec CU..
    &quot;The opinions expressed here represent my own and not those of anybody else&quot;

  • Hello, we have both Creative Cloud and Creative Cloud for teams. Can you help me with the difference and if i need to have both?

    Hello, we have both Creative Cloud membership and Creative Cloud for team. Can you help me with the difference and if i need to have both? We have 9 employees that are using it. Just not sure if i'm paying for something i don't need.
    Thank you

    Please refer to Creative Cloud Help | Creative Cloud / Common Questions
    CC is for retail use with 20 GB of storage space, CCT is where number of seats are purchased & assigned by one program admin where each seat gets 100GB of storage space.
    You can not have both the CC & team in one account as it will only provide you added storage space of 120 GB but you can activate the CC any of them or either of them twice as CC is based on Adobe ID.
    Regards
    Rajshree

  • Need lightroom 4.4 asmac is 10.6.8 and not compatible with anything higher. Does this come with the creative cloud? Would really like a disc but that doesn't seem to happen anymore. Currently have cs4 and d7100 hence need 4.4 to open raw Any idea

    need lightroom 4.4 asmac is 10.6.8 and not compatible with anything higher. Does this come with the creative cloud? Would really like a disc but that doesn't seem to happen anymore. Currently have cs4 and d7100 hence need 4.4 to open raw Any ideas? Is this now customer service or does adobe have a customer service team . Site not user friendly. Thanks

    Graham Giles wrote:
    Have you seen this type of problem before? I think it could be a serious issue for anyone in a similar position.
    No; but then, I've not had occasion to use TDM. I've been using firerwire drives for over 10 years, both FW400 and FW800, with no issues except a bit of instability using a B&W G3 machine.
    TDM should be safe. Using cautious, manual copying of files from the Target machine to the Host machine should not result in unexpected loss of files or damage to the Target drive's directories. It should behave exactly the same as if it were an external (to the Host) firewire drive.
    •  I don't suppose there is anything I can do to 'put back' lost items from a separate Time Machine drive which has an up to date backup on it.
    There is probably a way to do that - seems to me that's one of the reasons for a Time Machine volume.
    On the other hand, if the Time Machine volume is rigidly linked to the now-absent OS on the original drive, there may be no way to effectively access the files in the TM archive.
    I know that using a cloned drive would work well in this instance.
    I have no experience with Time Machine, so perhaps someone who has will chime in with suggestions.
    With the machine in TDM with the other machine, have you tried running Disk Utility to see if you can effect repairs to the drive?

  • HT3986 I've had MS Office:mac 2011 on my imac for around 18 months now.  Outlook has just disappeared and when I find the file and open it it tells me that there is a problem and I may need to re-install it.  I've just done this using the installation dis

    I've had MS Office:mac 2011 on my imac for around 18 months now.  Outlook has just disappeared and when I find the file and open it it tells me that there is a problem and I may need to re-install it.  I've just done this using the installation disc which, then said the installation had been successful.
    Outlook is still not working.  Can anyone please advise me on what to do next.

    Remove MS Office 2011 completely (here are instructions) and reinstall it.
    It's not a simple or fast process but it is important to follow all of the steps in order to get all the files that Office scatters around. This will not affect your data files, only MS Office and its preferences.

  • Upgrade of our 10.4.11 laptop to 10.5 is accomplished and we now need to upgrade Quicktime and iTunes; however, the user name and password is now not working after the upgrade to 10.5.

    Object is to sync address and calendar between laptop with Max OS 10.4.11 and iPhone. Upgrade of our 10.4.11 laptop to 10.5 is accomplished and we now need to upgrade Quicktime and iTunes; however, the user name and password for the laptop is now not working after the upgrade to 10.5., though it was working prior to the upgrade, for file sharing.

    @ BDAqua > I tried your suggestion but no luck. holding opt+command just gave me a blue screen and it rebotted, pushing the disk out of the drive. Yes, the macbook has 1 gb of ram. I realize that the min req. call for 2 gb of ram so i've got an order in for another dimm to put into the machine. Thanks for your suggestions.
    @ a_brody > Yes. The machine was plugged into a power source. The disk promts you to do that and i recall aspect this form other installs. Thanks for the reminder tho! ( btw your second post is like greek to me man!) 
    @ Kuncklesmac > You're right about Snow Leopard being an upgrade from Leopard. I'm aware of this. And yes previously i've been told by Apple that I needed the Box Set (not the family pack.  i am using the family pack for OS Snow Leopard) to upgrade my 10.4.11 mac - they never mentioned adding ram but i figured that out on my own and an apple specialist recommended it when i purchased Snow Leopard and confirmed that I coul duse the Snow Leopard to upgarde from Tiger (10.4.11). I've also read extensively (as i said above) that it isn't necessary (always) to buy the box set. Several 10.4.11 users report having upgraded using the Snow Leopard upgrade disk only (not the Box Set) without trouble on intel macs (also see the apple link i posted). So i'm just ondering how they did it and i cannot. 
    Thanks fo rall yor help!

  • I have updated to itunes 10.5 and now it doesn't recognize our iphones and says we need a driver installer but then throws a notice saying an error occured. Anyone know anything about this?  :)

    I have updated to itunes 10.5 on my Mac computer and now it doesn't recognize my iphones and says i need to install a device driver but when i try to install it it throws up a notification saying an error occured and to contact the makers of my device 's suppot website.  Anyone know?

    Have you tried repairing your application from within the Control Panel?

  • My ipod touch is telling me that the skype and twitter apps need updating. When I try to run them they fail. I have tried deleting the apps via itunes but it doesn't work and I have tried updating the apps via itunes and it says they are updated.

    My ipod touch is telling me that the Skype and Twitter apps need updating.  When I try to update them they both fail. I have tried numerous times.  I have tried connecting the ipod to itunes and removing the apps, to reload them but that does not work either.  If I try and update the apps through itunes the system tells me they are updated.  Can anyone assist please?

    - Try a reset. It cures amny ills
    Reset iPod touch:  Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Have you tried deleting them from the iPod and then redownloading them dorectly to the iPod?
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • Have CS5 and CS6.  Need to reduce size of file from 6Mb to 2 Mb for contest purposes without losing original

    Have CS5 and CS6.  Need to reduce size of file from 6Mb to 2 Mb for contest purposes without losing original

    Just save the document to a new jpeg file name using a lower quality setting or re-size the image down in  size the save a high quality smaller new jpeg image.

  • I have a macbook pro with a mini display port out and would like to know how to connect the video from my mac to a TV with old RCA input video, or a TV with S-video imput. How can I do this, and do I need a video converter?

    I have a MacBook Pro that I want to hook up the Mini Display Port video out to a TV with RCA video imput, or a TV with S-video iimput.
    How do I do this, and do I need a video converter?
    Dennis

    there's an adaptor for mini dvi to s-video
    a well known auction site would yield results if apple don't stock it

  • My Apple TV all of a sudden refuses to show my movies from my MacBook and says it needs to set time network. What is that?

    My Apple TV all of a sudden refuses to show the movies from my MacBook and says it needs to set time network. What is that?

    Welcome to the Apple Community.
    The Apple TV should set it's time automatically from the network time server, if it isn't doing this try restarting the Apple TV by removing ALL the cables for a 30 seconds, if this fails try resetting or restoring it.

Maybe you are looking for