JDBC Data Source and SQL Queries

Harry · 24 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

Query-Based Reports

Instead of beans, embed SQL directly: in Jaspersoft Studio create a Data Adapter → JDBC, then write the query in the Dataset dialog. Fields are derived from the result-set columns.

<queryString>
  <![CDATA[SELECT name, salary FROM employees WHERE dept = $P{dept}]]>
</queryString>

SQL query feeding report fields

Filling from a Connection

try (Connection con = dataSource.getConnection()) {
    JasperPrint print = JasperFillManager.fillReport(report, params, con);
}

Use $P!{...} syntax when a parameter must be spliced into SQL (e.g. an ORDER BY column) rather than bound.

Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in