Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

java - how to save pdf reports automatically in database?

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

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

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...