Is it possible to download or view a file directly from a database using JSP and JDBC? For example, I have a jpeg file stored as a BLOB in a database. Is it possible to place it on a page directly from the db without saving it first as a file. What about other file types (*.exe, *.pdf ...)?

Mohd Hatta

You'll have to use a servlet for this purpose and include it within your JSP page. Based on the question, let me assume that the database storage is Oracle.

Since this is just a simple example, the assumption is that all JDBC access is available within the servlet.

1. import the sql classes from the Oracle classes. (reason to use the BLOB and CLOB data type)

2. this step is optional, make sure that set content type is made to "image/gif" or "image/jpeg"

3. open the connection

4. retrieve the the data and place it to the BLOB data type object.

5. close the connection

6. transfer the BLOB object into byte arrays and use java.io.OutputStream to display the values.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact