[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: jdbc/informix/pdf question



Just a guess, but I think that the 'byte' field represents a boolean value
indicating whether or not there's a PDF file associated with the record. I
believe that a PDF would have to be stored in the database as a blob, but I
don't see such a field in your schema.

Again, just a guess, but one of the varchar fields may indicate a directory
path to a PDF file that's stored on the file system, and another the actual
name of the file or the file extention.  You can check the actual data to
get a better idea.

If the PDFs are stored as files, below is a simple example for streaming a
PDF to a browser from a file on the server side, that I used for a training
class.

Good luck!
Allan

---------------------

package simplePDFServlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class RetrievePDF extends HttpServlet {

    static final private String CONTENT_TEXT = "text/html";

    //Initialize class variables
    public void init() throws ServletException {
    }

    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse
response)
                                            throws ServletException,
IOException {

        // Create a new File object (subsitute the correct drive letter,
        //  path and filename below)
        File file = new File("[drive]:/[directory path]/[filename].pdf");

       if (!file.exists()){
            PrintWriter out = response.getWriter();
            response.setContentType(CONTENT_TEXT);
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<H1> ERROR - FILE DOES NOT EXIST </H1>");
            out.println("</BODY>");
            out.println("</HTML>");
        } else {
            response.setContentType("application/pdf");
            ServletOutputStream out = response.getOutputStream();
            int filesize = (int) file.length();
            byte[] data = new byte[filesize];
            DataInputStream in = new DataInputStream(new
FileInputStream(file));
            in.readFully(data);
            in.close();
            out.write(data);
            out.close();
        }
    }

    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse
response)
                                            throws ServletException,
IOException {
        doPost(request,response);
    }

    //Clean up resources
    public void destroy() {
    }
}

-----Original Message-----
From: Jones, Ashley C [mailto:Ashley.Jones@bellsouth.com]
Sent: Wednesday, June 11, 2003 4:44 PM
To: ajug-members@ajug.org
Subject: jdbc/informix/pdf question



OK Interesting situation here and I'm not really sure how to begin so I
thought
this might make an interesting discussion.

I'm rewriting an interface to an informix database.  In this database are
records which
contain attachments in pdf format.  These attachments are stored in the
database as Type
Informix byte.

for example

Column name		Type		Nulls
----------------------------------------------------------------------------
colname1		varchar(25)	no
colname2		varchar(25)	no
attachment_name	varchar(5)	no
attachment		byte		yes

In the Informix Driver JDBC Docs there is a IfxTypes.IFX_TYPE_BYTE

What I would like to do is when someone wants to view the attachment have it
queried from the
database and then imbedded into a browser window for viewing.  From there
the user can close
or save the file.

The way it is done now in the previous application is the file is extracted
to a temporary directory
on the server and using anonymous ftp it is viewed by the user.

Has anyone done anything like this before?

I'm thinking that I can use ResultSet.getBinaryStream() to retrieve the data
from the database and read it into
a File object.  From their send it to be embedded in a browser window( not
sure how to do this part )

Thks
Ashley Jones
BellSouth




*****
"The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential, proprietary, and/or
privileged material.  Any review, retransmission, dissemination or other use
of, or taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited.  If you received
this in error, please contact the sender and delete the material from all
computers."