|
what exactly is the problem?
Does the PDF not come out of the DB, or does it come out
but not make it to the browser?
Have you saved the PDF out of the DB to a file and looked
at it?
-Bill Ensley
Bear Printing From: Greg Critcher [mailto:[EMAIL PROTECTED] Sent: Friday, February 03, 2006 7:44 AM To: 'Bill Ensley' Subject: RE: [iText-questions] Can't save an itext pdf to my oracle database. Sorry for the lack of clarity.
I can produce the pdf to a browser without problem. It’s the bytes to the database that I’m having problems with.
Here is the code.
The servlet goes like this. After I create the pdf, I send the ByteArrayOutputStream baos to a db bean.
AcceptanceDB myAcceptanceDB = new AcceptanceDB(userProfile.getLoginID(),userProfile.getPassword()); myAcceptanceDB.insertProjectPdf(ProjectID,baos.toByteArray());
Here’s the insert db bean.
InsertSQL = "INSERT into Project_Pdf (Project_Pdf_ID, Project_ID,Award_Contract_Pdf) " + "values (PROJECT_PDFSEQUENCE.NextVal, ? , empty_blob())"; //+ projectID + "','ASR')"; myPreparedStmt = tempConn.prepareStatement(InsertSQL);
myPreparedStmt.setString(1, projectID); log(InsertSQL); result = myPreparedStmt.executeUpdate();
myStmt.executeQuery("commit");
String cmd2 = "update into Project_Pdf (Award_Contract_Pdf) values (?) where Project_ID = '" + projectID + "'"; myPreparedStmt2 = tempConn.prepareStatement(cmd2); ByteArrayInputStream bais = new ByteArrayInputStream(AwardContractPdf); myPreparedStmt2.setBinaryStream(1, bais, AwardContractPdf.length);
myStmt.executeQuery("commit");
Then I retrieve the data with the following.
String sql = "SELECT Award_Contract_Pdf FROM Project_Pdf WHERE Project_ID ='" + ProjectID + "'"; log(sql);
ResultSet rs = sment.executeQuery(sql); if ( rs.next() ) { returndata = rs.getBytes("Award_Contract_Pdf");
} Then try to write to browser with the following.
byte[] PdfBytes = myAcceptanceDB.getProjectPdf(ProjectID); log("PdfBytes" + PdfBytes.length);
baos.write(PdfBytes, 0, PdfBytes.length); log("baos.size" + baos.size()); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // setting the content type response.setContentType("application/pdf"); // the contentlength is needed for MSIE!!! response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream ServletOutputStream out = response.getOutputStream();
baos.writeTo(out); out.flush();
Any help would be great. I past my deadline.
Greg -----Original
Message-----
This is really not enough information to help you.
Is the problem that a valid PDF is not being created, but the bytes are going into the database? Is the problem that valid PDF IS being produced, but not going into the database?
I recommend you break this problem out into seperate issues:
First confirm that a valid PDF is being produced and save it to a File Stream.
Second, use a file stream to read that PDF into your database.
If these two things work, then you know that the problem is in how you are saving your bytes to the DB.
-Bill Ensley Bear Printing
From:
[EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Greg Critcher I have code that complies correctly but it’s not working. Anybody have code that works.
Greg |
- [iText-questions] Can't save an itext pdf to my oracle datab... Greg Critcher
- Re: [iText-questions] Can't save an itext pdf to my ora... Bruno Lowagie
- [iText-questions] Re: Can't save an itext pdf to my... Bruno Lowagie
- RE: [iText-questions] Can't save an itext pdf to my ora... Bill Ensley
- RE: [iText-questions] Can't save an itext pdf to my ora... Bill Ensley
