0

How can i open/view .pdf/.doc files that are save in database? I have this class name FileAttachment:

...
private Object file;
private String fileName;
//getter and setters

and on my Dao Class i called my longblob datatype:

Blob file;
if(rset.getBlob("file")!=null){
    file = rset.getBlob("file");
}else{
    file = null;
}
attachment.setFile(file);
attachment.setFileName(rset.getString("file_name"));

My concern now is How do i open/view this file on my application?. I tried something like this:

private void lblFileContentMouseClicked(java.awt.event.MouseEvent evt) {                                            
try {
      File file = new File(attachment.getFile().toString());
      System.out.println("file "+file);
      if(file.exists()){
          Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+file);
                  p.waitFor();
        }else{
            System.out.println("File is not found ");
        }
 ...

However, it does not work.

Any help is much appreciated

Anirudh Lou
  • 781
  • 2
  • 10
  • 28
  • Do you want this application to launch this file on your PC having respective software installed? Also, you need to make sure that the filename exists along with the correct extension. – Am_I_Helpful Mar 04 '18 at 12:08
  • Yeah, for example when i click the file it will open, if .doc, word will open along its content same with pdf and other. – Anirudh Lou Mar 04 '18 at 12:45
  • Possible duplicate of [Launch file from Java](https://stackoverflow.com/questions/847838/launch-file-from-java) – Am_I_Helpful Mar 04 '18 at 12:46
  • As i read some article, i need to put my file it on temporary folder? How can i put it on my src(default package)? – Anirudh Lou Mar 04 '18 at 12:51

0 Answers0