• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

Problem in setBinaryStream when using SequenceInputStream

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help here is the java code




I'm getting this error

Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.T4CPreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V
at com.svi.blob.Main.saveBlob(Main.java:56)
at com.svi.blob.Main.main(Main.java:36)

Thanks,
 
Sheriff
Posts: 22743
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rey, welcome to the Ranch!

Could you please UseCodeTags next time? I've added them for you this time, and look how much nicer it looks.

As for the problem, you're calling PreparedStatement.setBinaryStream(int, InputStream, long) because the casting to int only applies to file1.length(). By adding file2.length() you're turning the thing into a long again. The problem is that that method was added in Java 6.

There are two solutions:
1) apply the cast to the result of the addition: (int)(file1.length() + file2.length())
2) update your Oracle drivers to one that supports the features added in Java 6

Personally I'd go for the second, because then the code you compile will actually work.
 
Renz Cruz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob thank you for that quick reply it solved my problem. I have another question now I can put many files in one blob in my db, can you please suggest a way how can i retrieve the blob and split it to get the original form of the files?


Thank you for your help.
 
Rob Spoor
Sheriff
Posts: 22743
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not a good way to do it frankly. If you still want to do it you must specify where one file ends and another one starts. One way to do this is use a DataOutputStream (and DataInputStream for reading back). First write the size of the file, then write the file. Then write the size of the next file, write the next file, etc.

Reading is then just as easy: first read back the size, then read exactly that many bytes. Read the size again, read bytes again, etc. You may want to add a -1 after all files so you'll know you're done reading when the size is -1.
 
Renz Cruz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you saying that I need to rewrite the files? Read the files and then write it to a new file using DataOutputStream, write first the size of the file, then write the file?

Can you comment on my code I'm using .skip to get the file that I need I think its simillar to your solution.





Thank you.
 
Rob Spoor
Sheriff
Posts: 22743
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you know where each file starts? You should add a few more InputStreams, for the lengths.
The reading:
The -1 is added so you know when to stop when iterating through all files:
 
Renz Cruz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there is some problem in the code



and




Please make it clear because I'm new with java.

Thanks,
 
Rob Spoor
Sheriff
Posts: 22743
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Renz Cruz wrote:


Sorry, that should be DataOutputStream of course.


The way I've written the files to the database is as follows:
1) the file size in 4 bytes; DataOutputStream converted the long to bytes
2) the file contents
3) steps 1 and 2 again
4) steps 1 and 2 again
5) -1 in 4 bytes

Because I've used DataOutputStream to convert one long into 4 bytes I used DataInputStream to do the inverse - convert the first 4 bytes back into a long. This is the size of the first file (step 1).
Because you wanted the second file we can skip the entire first file. That's what the dis.skip(size) does* (step 2). You then read the size of the second file (step 3, part 1) and the file (step 3, part 2).


* Actually this code has a potential flaw. skip is allowed to actually skip less. skip should instead be looped until all is really skipped:
This tries to skip the remaining size each time, subtracting the actual number of skipped bytes. So if size starts at 20 and the first time only 16 bytes are skipped, size becomes 4 and skip is attempted again.
 
Renz Cruz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob thank you for your help I really appreciate it.
 
Rob Spoor
Sheriff
Posts: 22743
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic