Java Progress Upload of BLOB
530854Dec 18 2006 — edited Feb 11 2007Hello 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