Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My programming language is java. My application is a web based application. I am using BIRT for generating pdf reports but the requirement is to automatically save them to the database after viewing the pdf report. In BIRT the pdf document is generated on the fly from the rpt templates. When user clicks on a URL the pdf document is displayed by the BIRT viewer application.

The requirement is once the pdf is generated i need to save a copy of the pdf file in the MySql database. This should happen automatically. once the user views the pdf (when the pdf is generated on the fly) the copy of the pdf file should get saved in the database.

Please let me know, how i can achieve this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
195 views
Welcome To Ask or Share your Answers For Others

1 Answer

It depends con how you use your database, direct jdbc, hibernate, ... But basically you have to do following:

  • design an entity (and table) to hold the blob.
  • don't use BLOB in MySQL is very small, better LONGBLOB.
  • create a java.sql.Blob from file, usually you have to get an inputstream from file.
  • attach blob to hibernate entity, query param, ...
  • persist.

I would rather prefer to store files in a different entity/table, and also store file name, size, MIME type, date, ... These attributes will be helpful later.

Use a 1:1 por 1:N relationship between the entity owning the file and the file entity.

Hope it helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...