Problem storing dynamically created PDF file in a db2 table as a blob

T

Tony

Hi,
I have dynamically created a PDF document in memory as a FileOutputStream
Now I have to get it into a DB2 table, storing it as a BLOB. The table has a
document id,
document name, some date fields and this BLOB column that stores PDF Files.
Until now, the PDF files were read off of a disk drive. The code used was:

byte[] fileAsBytes = (byte[]) adminDocEvent.getFile();

which returns an object.
then:
"INSERT INTO WPWDB.DOC_DOCUMENT ("
+ "DOC_SUB_CAT_ID,"
+ "DOC_DOC_NM_TXT,"
+ "DOC_DOC_DESCN_TXT,"
+ "DOC_ACTIVE_TXT,"
+ "DOC_DOC_LNK_TXT,"
+ "DOC_DOC_MIME_TYP,"
+ "MODIFY_USUS_ID,"
+ "MODIFY_DT_TM)"
+ " VALUES (?,?,?,?,?,?,?,CURRENT TIMESTAMP)";

connection = getConnection();

pstmt = connection.prepareStatement(query);
pstmt.setInt(1, subCatId);
pstmt.setString(2, docName);
pstmt.setString(3, docDescription);
pstmt.setString(4, "Y");
==> pstmt.setBytes(5, fileasarray);
pstmt.setString(6, mimeType);
pstmt.setString(7, modfiedUserID);
pstmt.executeUpdate();

This is fine, if the pdf file exists as a file on a disk.
For my issue (loading a pdf file from memory) I use the following:

FileOutputStream fos = new FileOutputStream(docName);
private PdfWriter docWriter = null;
docWriter=PdfWriter.getInstance(pdfDocument, fos);
I then create the pdfDocument in memory using iText classes.
Then I try to prepare the file for the above sql stmt.

file = (Object) fos;
AdminDocDAO adminDocDAO = new AdminDocDAO();
if (adminDocDAO.addDoc(subCatId,docName,docDescription,fileAsBytes,
mimeType,modifiedUserID))

I get a casting exeception at: file = (Object) fos;

So my question is can anyone think of another approach to getting a
FileOutputStream into a format loadable in SQL using DB2???????
Thanks to any and all who can.
 
M

Murray

Tony said:
Hi,
I have dynamically created a PDF document in memory as a FileOutputStream

<snip/>

No need to cross-post.

See my answer in comp.lang.java.databases
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top