I. Requirement
Scenario: If you save ready-made template files on the hard disk, once the hard disk fails or crashes, the template files may be missing irreversibly, which will cause bad consequences.
Function: To lower the risks of template file missing, the function enables you to save all finalized template files into the database. In this way, even if the hard disk crashes, you can still extract these template files from the database for backups.
Save a .cpt template file into MySQL database. Click the dataset named report and then click DB Query>Dataset. Type SELECT * FROM REPORT.
A Preview window pops up, as shown in the figure below:
How to save a .cpt template file into the database? Specific steps are shown below.
II. Steps
1. Create a report in database
Create a report in the database. The report should contain two fields, cptname (string) and cpt (Blob).
2. Edit codes for saving the template
Note: It is necessary to introduce the JAR package under FineReport’s designer. Detailed codes are listed below:
See the specific steps in Start the Designer in Eclipse.
Note: This program connects to the database with JDBC. Before editing codes, load the driver package of the corresponding database into project.
Additionally, some codes should be modified according to actual report-related environment path and database.
Moreover, if the database is case insensitive (which means treating or interpreting upper- and lowercase letters as being the same), it is not necessary to modify the codes; if the database is case sensitive, add double quotation marks to the report name, that is, insert into \"report\" values(?,?)
III. Compiling and execution
Run the compiled program and you will find newly added data are displayed in the database.