Skip to Main Content

Java and JavaScript in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Progress Upload of BLOB

530854Dec 18 2006 — edited Feb 11 2007
Hello hello,

I want to upload a BLOB into a Database.

FileInputStream fis = new FileInputStream(file);
PreparedStatement pstmt =
cm.getCon().prepareStatement("insert into cip_docufiles (filename, document, docuid) " +
"values ('" + filename + "', ?, " + docuID + ")");
pstmt.setBinaryStream(1, fis, (int)file.length());
pstmt.executeUpdate();

By doing this I give the Stream to the Statement, but I can't get how much bytes are transfered already. Is there another method to upload a file analog to the following download method?


InputStream blobStream = blob.getBinaryStream();
FileOutputStream fileOutStream = new FileOutputStream("." + cm.sep + cm.tempDir + cm.sep + fileName);
byte[] buffer = new byte[4096];
int nbytes = 0;
int bytesTransfered = 0;
while((nbytes = blobStream.read(buffer)) != -1) {
fileOutStream.write(buffer, 0, nbytes);
bytesTransfered += nbytes;
System.out.println("Bytes " + bytesTransfered + " block " + nbytes);
}

Here I can print out the actually transfered bytes.

thanks for help...
regards phil
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 11 2007
Added on Dec 18 2006
17 comments
6,202 views