HOME > SUPPORT > SIMPLE JDBC REPORTS

Simple JDBC Reports

 

Overview

ReportMill works with any kind of Java dataset: EJBs, custom Java classes, Java Collections classes, JDBC ResultSets or any combination/hierarchy of the above. ReportMill is most powerful when used with EJBs and custom Java classes (perhaps loaded with an object-relational mapping tool), because it can take advantage of custom business logic in your derived attribute methods. However, sometimes it can be convenient to make a quick JDBC fetch and generate a report on the results.

Here's an example of a few simple lines of code to do that:

  // Get DB Connection info
  String url = "jdbc:mydbdriver://mydb.domain.com/test";
  String user = "whoever";
  String password = "whatever";

  // Get connection and execute SQL Query
  Connection db = DriverManager.getConnection(url, user, password);
  Statement st = db.createStatement();
  ResultSet resultSet = st.executeQuery("select * from MY_TABLE");

  // Generate XML for ResultSet (only do this once to get XML dataset for designer)
  new RMXMLWriter().writeObject(resultSet, "C:/Dataset.xml");

  // Load template from aSource (File, String path, InputStream, URL, byte[], etc.)
  RMDocument template = new RMDocument(aSource);

  // Generate report from result set and get PDF
  RMDocument report = template.generateReport(resultSet);
  byte pdf[] = report.getBytesPDF(); // or report.write("/tmp/MyReport.pdf")

 

JDBC in the Design Application

ReportMill does offer JDBC connection and query definition in the design application's "Connect to DataSource" panel. This allows you to define a template based on a simple query. However, it is generally expected at runtime the data will be provided using JDBC code similiar to the above.