Re: please confirm something (jdbc)
"Thomas Kellerer" <YQDHXVLMUBXG@spammotel.com> wrote in message
news:5r78t1F11guqlU1@mid.individual.net...
Could well be. When I tried to find a way to support LOB data across
different DMBS, getBinaryStream() (and set..) was the only method that
worked reliably (using an Oracle 10.x driver)
I've downloaded the driver but still can't make it work. Here's the code:
// write
conn.setAutoCommit(false); // because some data is stored in other tables as
well
PreparedStatement pstmt = conn.prepareStatement("insert into test (id,
content) values (?, ?)";
pstmt.setString(1, "12345");
pstmt.setBinaryStream(2, bais, bais.available()); // bais contains bytes
read from the local PDF file
pstmt.executeUpdate();
pstmt.close();
conn.commit();
bais.close();
This works fine, that is, there are no exceptions, but is there a way to
check what is stored in the table using Oracle Enterprise Manager Console. I
got the warning that BLOB columns cannot be displayed. If I could only see
the length of bytes stored in the column, I could compare it to the size of
the PDF files locally on the disk.
And here's the code to read the BLOB:
// read
conn.setAutoCommit(true);
pstmt = conn.prepareStatement("select content from test where id = ? for
update";
pstmt.setString(1, "12345");
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
InputStream is = rs.getBinaryStream("content");
int n;
byte[] tmp = new byte[is.available()]; // available() returns 0!
FileOutputStream fos = new FileOutputStream("C:/Temp/12345.pdf");
while ((n = is.read(tmp)) != -1) {
fos.write(tmp, 0, n);
}
fos.close();
is.close();
}
rs.close();
pstmt.close();
conn.close();
The problem is that "available()" method returns 0 and "read()" method
blocks. What am I doing wrong?