Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.T4CPreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V
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.
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?
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.
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.