Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
public ResultSet performQuery(String query)
{
  final Properties prop = new Properties();
  prop.setProperty("user", "sa");
  prop.setProperty("password", "");

  // Note: You have to provide your own URL here
  final Connection c = DriverManager.getConnection
          ("jdbc:hsqldb:/home/src/pentaho/pentaho-jfree/sql/sampledata", prop);
  final Statement s = c.createStatement();
  final ResultSet resultSet = s.executeQuery(query);
  return resultSet;
}

Now we have the data, but Pentaho Reporting needs TableModels to work with. So let's wrap that resultset into a TableModel. The ResultSetTableModelFactory is part of Pentaho Reporting's core code.

Code Block
final CloseableTableModel model =
    ResultSetTableModelFactory.getInstance().createTableModel(resultSet);

The ".xml" file the tools created contain your report definition. Copy that file into a suitable location and obtain an URL to that xml-file. Use the 'executeReport' method from above together with your URL and the tablemodel and execute the report. After the reporting, don't forget to close the TableModel to free the ResultSet.