Urgent - pls help - Problem while inserting binary file into Oracle DB
Hi,
I am trying to insert binary files into a Blob column in a Oracle 10G table.
The binary files would be uploaded by the web users and hence come as multipart request. I use apache commons upload streaming API to handle it. Finally i am getting a input stream of the uploaded file.
The JDBC code is
PreparedStatement ps=conn.prepareStatement("insert into bincontent_table values(?)");
ps.setBinaryStream(1,inStream,length);
My problem starts when i try to find the length of the stream. available() method of inputstream does not return the full length of the stream. so i put a loop to read thru the stream and find the length as shown below
int length=0;
while((v=inStream.read())!=-1)
{
length++;
}
Now, though i got the length, my stream pointer has reached the end and i cant reset it(it throws an error if i try).
So i copied the stream content to a byte array and created an ByteArrayInputStream like this.
tempByteArray=new byte[length];
stream.read(tempByteArray,0,length);
ByteArrayInputStream bais=new ByteArrayInputStream(tempByteArray);
Now if i pass this bytearray input stream instead of the normal input stream to the prepared statement's setBinaryStream() method it throws an error as
"ORA-01460: unimplemented or unreasonable conversion requested".
Now how to solve this?
My doubts are ,
1) preparedStatement.setBinaryStream(int parameterIndex, InputStream x, int length) expects an inputstream and its length. if i have the stream how to find its length with out reading the stream?
2) Also as the length parameter is a integer, what if i have a large binary file whose length runs more than the capacity of integer
3) Alternatively there is a setBlob(int i, Blob x) in prepared statement. But how to instantiate a Blob object and set it here
4) Is there any better way to do this.
Thanks in advance

