Connect FineReport to an AnalyticDB for MySQL cluster to query data and build reports directly on your cluster.
Prerequisites
Before you begin, ensure that you have:
Reviewed the compatibility between FineReport and AnalyticDB for MySQL. See Compatibility overview.
Installed MySQL Connector/J.
Installed FineReport. If this is your first time installing FineReport, you also need a MySQL server (such as ApsaraDB RDS for MySQL) to import FineReport metadata. Use either of the following methods to set up the connection:
FineReport designer: For MySQL 5.x, see [Platform] Connect to MySQL. For MySQL 8.x, see [Platform] Connect to MySQL.
Data-based decision making system: See [Designer] Connect to a database.
(Optional) Applied for a public endpoint if connecting over the internet. See Apply for or release a public endpoint.
Connect to AnalyticDB for MySQL
Connection parameters
| Parameter | Value |
|---|---|
| Database | MySQL |
| Driver | com.mysql.jdbc.Driver |
| URL | jdbc:mysql://<hostname>:<port> |
| Username | Privileged account or standard account |
| Password | Account password |
Where:
<hostname>: the public or Virtual Private Cloud (VPC) endpoint of your cluster.<port>: the port of the cluster endpoint. Default:3306.
Steps
Start FineReport. In the top menu bar, choose Server > Define Data Connection.
In the Define Data Connection dialog, set the parameters shown in the table above.

Click Test Connection. After the test passes, click OK.
You are now connected to your AnalyticDB for MySQL cluster. Next, create datasets to query data for your reports.
Create a dataset
A dataset contains data retrieved from your cluster using SQL statements. FineReport displays datasets as two-dimensional tables in the dataset management panel.
Click the Template Dataset tab, then click the + icon in the upper-left corner.

Select DB Query from the drop-down list.

In the DB Query dialog, set Name to
ds1. Select your AnalyticDB for MySQL cluster from the drop-down in the upper-left corner. Click a table in the left-side list, then enter your SQL in the right-side editor. For example, to retrieve all data fromdemo_sales:select * from demo_sales
To create an aggregate dataset, add another dataset named
ds2. For example, to get total sales by store:SELECT <Store name>, SUM(Revenue) AS <Total sales volume> FROM demo_sales GROUP BY <Store name>Click OK. The retrieved data appears in the dataset management panel.
Build a report
This section walks through a complete example: a report with tables and column charts showing maximum and total sales volumes by product type, payment type, and contract type.

Set up the demo data
Download the demo_contract table.
Create the
demo_contracttable in your AnalyticDB for MySQL cluster. Use a column with evenly distributed values as the distribution key and a time column as the partition key. See Table schema design for guidance. In this example,contract_idis used as the distribution key because its values are randomly distributed:Create Table `demo_contract` ( `contract_id` varchar, `customer_id` varchar, `contract_type` varchar, `amount` bigint, `payment_type` varchar, `register_time` date, `purchase_amount` int, `create_time` timestamp, `product_type` smallint, `paid` tinyint, primary key (`contract_id`) ) DISTRIBUTED BY HASH(`contract_id`) INDEX_ALL='Y' STORAGE_POLICY='COLD'Import data from the XLSX file to AnalyticDB for MySQL using Kettle. See Use Kettle to import data to Data Warehouse Edition. After the import, run the following to verify the data:
SELECT count(*) FROM demo_contractThe query returns 668 entries.
Import datasets into FineReport
Create two datasets in FineReport using the imported data.
Create dataset
d1to get the maximum sales volume by product type, contract type, and payment type:select product_type, payment_type, contract_type, max(purchase_amount) as max_amount from demo_contract group by product_type, payment_type, contract_type having max_amount>0Create dataset
d2to get total sales by product type and contract type: Categorize data by product type and contract type, and calculate the total sales volume across all payment types.

Design the table
Title: Merge cells A1 to D2. Enter
Contract Sales Overviewin the merged cell, set the font size to 15, and make it bold and centered.Angled header: Merge cells A3 and B3. Right-click the merged cell and choose Cell Element > Insert Slash. In the Slope Line dialog, enter:
Payment Type | Contract Type | Product TypeAdd spaces to adjust text positions.


Formulas: Drag the data columns with uneven value distribution to the corresponding cells. Then add the following formulas:
Click cell C5. Click the Insert Formula icon in the shortcut bar. In the Formula Definition dialog, enter
SUM(C4)to sum total sales by product.Click cell D5 and add
SUM(D4)to sum total sales across all products.

Expansion directions: Control how data expands across cells.
Click cell C3. In the panel, click Cell Attributes > Expand tab. In the Basic section, set Expand Direction to H so product type data expands horizontally.
Set Expand Direction to No Expansion for cells C4, C5, and D5, because these cells hold unique values tied to specific combinations.

Dataset association: When multiple datasets appear in the same report, link them using shared fields. Datasets
d1andd2both containproduct_typeandcontract_type, so use these fields to associate the two datasets. Double-click cell D4. In the Data Column dialog, click the Filter tab and add a common condition to linkproduct_typeandcontract_typeacrossd1andd2.

Add a column chart
Merge cells A7 to D15. In the top menu bar, choose Insert > Cell Element > Insert Chart. Select Column Chart from the Chart Type list, choose Column Chart in the right-side list, and click OK.

Click the chart. In the panel, click Cell Element. On the Data tab, set the following:
Data Source: Cell Data
Category:
=B4Series:
=C3Value:
=C4
NotePrefix each cell reference with
=. Without the=, FineReport treats the value as a string instead of a cell reference.
Preview the report
Save the report first, then click Preview and select Pagination Preview from the drop-down. The report opens in your browser.