I have been looking for an answer for this extensively and I am sure the answer is simple enough.
I want to use the Connection/Datasource Name as the title for a chart that I run against multiple databases.
For example I have one template and run it against different databases that contain the same schema. Without manually updating the template every time I thought it would be easy to grab the title of the chart from the data开发者_开发技巧source/connection as this is unique.
I am looking specifically for the field expression to grab this information.
Thanks!
$P{REPORT_CONNECTION}.getCatalog()
$P{REPORT_CONNECTION}.getCatalog() is a good answer.
Keep in mind that you have more flexibility if that's not precisely what you want. You could, for example, put things like this into your chart title as well:
$P{REPORT_CONNECTION}.getMetaData().getDatabaseProductName()
$P{REPORT_CONNECTION}.getMetaData().getUrl()
etc.
EDIT: The parameter $P{REPORT_CONNECTION} is a JasperReports/iReport creation in one sense... but really it's just a java.sql.Connection
. So you can see the methods in JDBC reference documents.
$P{REPORT_CONNECTION}.getMetaData().getDatabaseProductName()
精彩评论