GeeCON Prague 2014*
The moose likes Java in General and the fly likes retrieving file from database and then displaying it using appropriate program! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "retrieving file from database and then displaying it using appropriate program!" Watch "retrieving file from database and then displaying it using appropriate program!" New topic
Author

retrieving file from database and then displaying it using appropriate program!

honey singh
Ranch Hand

Joined: Apr 26, 2002
Posts: 44
Hi gurus,
I'm actually little bit new to this java world..I'm making a project using java and oracle8i in which the users can upload the files of any type say .txt,.gif or any type to the oracle database. now from the GUI the user can select the file and it can be updated to the database using the BLOBS.. this is working fine, but the problem is with the next step..when the user is presented with the different GUI to view his additions in the database, then when he clicks on any file..so it must open on its own....I mean if it is .txt file then clicking on that file name the notepad must open with the contents of the file, if it is .gif file then appropriate program to execute this must open...
Now this has been a big hurdle to me in making my project. I had heard that it can be done using the servlets by the setting the mime types, but I'm not clear about this....or I have to access the OS which is windows NT to find the appropriate program to run the file, but I don't know how to to do this.
Please if anybody can help me in this case with some alternative..
thanx.
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
If you select the data from the database, you get it as byte[] data. Store this in an object (such as a custom File implementation). The GUI would hit a servlet and pass it enough info so that it can retrieve the object just described. Now the servlet can set the content type to the type the object says it is and, using a raw output stream (as opposed to a printwriter) to write the data back to the requesting page. Something like this very abreviated version.

There are many factors to consider here (caching the images on disk is one) but this should be a good starting point. Hope this helps.
Sean
honey singh
Ranch Hand

Joined: Apr 26, 2002
Posts: 44
Hi Sean,
thanx very much for the reply, but please can u explain it in more detail, that how it is actually working? so if I try the code given by u, how is it being implemented? and also what is the other option of caching images to disk?
in other forum I saw this response:-
You need to set the mime-type and Content-disposition headers in your response. Set the mime-type as appopriate for the content, Content-disposition: inline; filename=<name> will give the browser a filename to pass into the helper app.
To be clearer:

response.addHeader("Content-type", "application/msword");
response.addHeader("Content-disposition", "inline; filename=\"test.doc\"");
I have also seen the filename reported in the Content-type header a la:
response.addHeader("Content-type", "application/msword; name=\"test.doc\"");
response.addHeader("Content-disposition", "inline; filename=\"test.doc\"");
so please it will be gr8 obligation to me if u can tell me in detail.
thanx in advance!
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879


This is the method in Windows that will open the file in the default program. Similar to double clicking the file in Windows Explorer.
Jamie
[ May 08, 2002: Message edited by: Jamie Robertson ]
honey singh
Ranch Hand

Joined: Apr 26, 2002
Posts: 44
Hi Jamie,
thanx for the repy, but it is giving exception
when I tried to compile it got compiled but when I tried to run it it gave the following exception
"java.io.IOException: CreateProcess: start C:\anim1.gif error=2"
the code is
import java.io.*;
class prog
{
public static void main(String args[])
{
try{
String filename="C:\\anim1.gif";
Runtime.getRuntime().exec("start "+filename);
}
catch(Exception e){System.out.println(e);}
}
}
I had tried like this also
Process p=Runtime.getRuntime().exec("start "+filename);
p.waitFor();
but this also gives me the same error.
what to do?
 
GeeCON Prague 2014
 
subject: retrieving file from database and then displaying it using appropriate program!