Hi,
I am using Oracle 9i as my DB Server.
I need to read the contents of a binary file (PDF) and store it into a
table within a column of type BLOB. So I am taking the contents of the
file into a FileInputStream object, opening a connection to the DB (and
the connection is getting established), using prepareStatement and then
setting the FileInputStream object using the setBinaryStream method. No
problem till here, but when I execute the (insert) statement with the
executeUpdate (or execute) command, this comes up:
java.sql.SQLException: Io exception: Connection reset
at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
.......
I should mention that the data is getting inserted into the table. But
this isnt a clean execution. I tried to close the connection and the
fileInputStream method but this exception is thrown before that. In
fact, no executed after the executeUpdate command.
Here is the relevant code, if it may be of help:
File file = new File("d:\\example.pdf");
fs = new FileInputStream(file);
Class.forName("oracle.jdbc.driver.OracleDriver");
connection=DriverManager.getConnection("jdbc:oracle:thin:@---","xxx","xxx");
connection.setAutoCommit(false);
pstmt = connection.prepareStatement("INSERT INTO PDFREADER (ID,PDFFILE)
VALUES (?,?)" );
pstmt.setInt(1,123);
pstmt.setBinaryStream(2,fs,(int)file.length());
pstmt.executeUpdate();
//lines below never get executed...
System.out.println("Execute called");
pstmt.close();
fs.close();
I will appreciate if someone is able to help me with this. I am stuck
on this since 2 days. I hope to get some help here.
Thank you,
Mladen Adamovic - 01 Nov 2006 15:30 GMT
Perhaps try to use some other method for updating blog value not
setBinaryStream with file?
perhaps read file into byte[] and see how you can set that to blog entry...
> File file = new File("d:\\example.pdf");
> fs = new FileInputStream(file);
[quoted text clipped - 13 lines]
> pstmt.close();
> fs.close();

Signature
Mladen Adamovic
http://www.online-utility.org
http://www.cheapvps.info
http://www.vpsreview.com
aditya2507@gmail.com - 02 Nov 2006 07:13 GMT
> Perhaps try to use some other method for updating blog value not
> setBinaryStream with file?
>
> perhaps read file into byte[] and see how you can set that to blog entry...
Thanks for your reply Mladen.
Yes I thought of that too. In fact we (guys at work here) did try to do
something similar but initially it didnt appear to work so we gave up.
>From all the reading done till now, the overall opinion that has formed
up is that this is a driver issue.
Thomas Kellerer - 01 Nov 2006 16:37 GMT
aditya2507@gmail.com wrote on 31.10.2006 10:55:
> Here is the relevant code, if it may be of help:
>
[quoted text clipped - 15 lines]
> pstmt.close();
> fs.close();
This works fine for me. But it might be a driver issue. My experience is that
older drivers do not implement the setBinaryStream() stuff correctly. Download
the latest 10g driver (will work with 9i without problems) and try it with that one.
Thomas
aditya2507@gmail.com - 02 Nov 2006 07:16 GMT
> This works fine for me. But it might be a driver issue. My experience is that
> older drivers do not implement the setBinaryStream() stuff correctly. Download
> the latest 10g driver (will work with 9i without problems) and try it with that one.
Right, could be that. Someone else too tried the code that I put here
and it seemed to work fine for him. So I guess there's nothing wrong
with the code. Also, I think if the OCI driver is used, this would work
-- I read that somewhere in a forum but it could be speculation, so I
can't be sure of that. Anyway, I got nothing to loose, will try the 10g
driver as well. Thank you for your reply Thomas, appreciate it.
Aditya Kumar - 03 Nov 2006 07:03 GMT
Well, I got it working. The problem was the jdbc driver.
But it is indeed strange, I was using the driver file ojdbc14.jar (the
one for version Oracle 9i), and it was throwing exception while
inserting Blob. I downloaded the new jar file for Oracle 10g (which is
supposed to be backward compatible) and its working with the 9i DB now.
No code change whatsoever.
Thank you for all your replies!
> > This works fine for me. But it might be a driver issue. My experience is that
> > older drivers do not implement the setBinaryStream() stuff correctly. Download
[quoted text clipped - 6 lines]
> can't be sure of that. Anyway, I got nothing to loose, will try the 10g
> driver as well. Thank you for your reply Thomas, appreciate it.