You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jasper Server 6.3社区版通过REST 2 API设置报表数据适配器

Dynamic Data Adapter Selection via JasperServer REST v2 API (6.3 Community Edition)

Great question—this is a super common use case when you need to reuse the same report across multiple pre-configured data sources. Let’s walk through the step-by-step solution to make this work:

Step 1: Update Your JRXML for Dynamic Adapter Input

First, we’ll replace the hardcoded data adapter path in your report with a parameter that can be passed at runtime. This keeps your report flexible while maintaining backward compatibility.

  1. Add a string parameter to your JRXML (include a default value to fall back on if no parameter is provided):
<parameter name="DATA_ADAPTER_PATH" class="java.lang.String" defaultValue="common/test.xml"/>
  1. Modify the existing data adapter property to reference this parameter instead of the fixed path:
<property name="net.sf.jasperreports.data.adapter" value="$P{DATA_ADAPTER_PATH}"/>

Step 2: Execute the Report via REST v2 API with Your Target Adapter

Now you can call the JasperServer REST v2 API to run the report, specifying your desired data adapter path in the request body.

Example cURL Request

curl -X POST "http://your-jasper-server:8080/jasperserver/rest_v2/reports/[YOUR_REPORT_REPOSITORY_URI]/exports/pdf" \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic [BASE64_ENCODED_CREDENTIALS]" \
  -d '{
    "parameters": {
      "DATA_ADAPTER_PATH": "common/another-db-adapter.xml"
    },
    // Optional: Add export-specific settings like page ranges
    "pages": "1-5"
  }'

Important Details:

  • Replace [YOUR_REPORT_REPOSITORY_URI] with the full path to your report in JasperServer (e.g., /reports/finance/monthly-forecast).
  • The Authorization header uses Base64 encoding of your JasperServer username and password (e.g., admin:admin becomes YWRtaW46YWRtaW4=).
  • The DATA_ADAPTER_PATH value must exactly match the path of the data adapter stored in your JasperServer repository—use the same path you see when navigating to the adapter in the web UI.

Step 3: Validate the Setup

To confirm everything works as expected:

  • Check JasperServer’s logs for entries referencing the data adapter path you passed.
  • Run the report with different adapter paths and verify the output matches the corresponding database’s data.

This approach works perfectly in JasperServer 6.3 Community Edition, letting you avoid maintaining duplicate report versions for different data sources.

内容的提问来源于stack exchange,提问作者Michael M

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:32:53