Wednesday, August 21, 2013

NextReports Engine: Integration Demo Hints

After you download nextreports-integration-demo from NextReports Site, you can run some sample code to see how to use engine api.

To make it easily for every java developer, from version 6.2, you can define a DemoDefinition class for your database. You can see such class for a Firebird connection, where you define database name, report /chart name, map of parameters and  database connection:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class FirebirdDemoDefinition implements DemoDefinition {

 public String getDatabaseName() {  
  return "Firebird Test";

 public String getReportName() {
  return "";

 public Connection createDemoConnection() throws ClassNotFoundException, SQLException {
        String url = "jdbc:firebirdsql:";
        System.out.println("Connect to '" + url + "'");
        return DriverManager.getConnection(url, "SYSDBA", "sysdba");
 public Map<String, Object> createDemoParameterValues() {
        Map<String, Object> parameterValues = new HashMap<String, Object>();
        return parameterValues;
 public String getChartName() {
  return null;

You just have to add your definition to DemoDefinitionFactory class and inside DemoUtil class change your NextReports home and your definition:
public static final String NEXTREPORTS_HOME = "D:\\Programs\\NextReports 6.2";
public static DemoDefinition def = DemoDefinitionFactory.get(DemoDefinitionFactory.FIREBIRD_DB);
This will help to test faster your JDBC driver compliance with NextReports.

Monday, August 05, 2013

NextReports: add your JDBC driver

Starting from version 6.2 NextReports will allow users to add their own JDBC drivers. We are using Vertica JDBC driver here as example. In version 6.2 Vertica driver will be added by default.

Such process can be resumed by following steps :

1. JDBC jar driver is added inside lib folder (designer and server). From 7.0, designer has a jdbc-drivers folder.

2. Driver must be added in driver_templates.xml which can be found :
  • inside designer in installation folder in \lib\nextreports-designer-6.1.jar 
  • inside server in installation folder in \webapps\nextserver\WEB-INF\classes 

3. You need to create a Dialect class for that type of driver. This dialect does a mapping between database types and java sql types and has some utilities methods.
import java.sql.Types;
import ro.nextreports.engine.util.ProcUtil;

public class VerticaDialect extends AbstractDialect {

    public VerticaDialect() {
     registerColumnType("binary", Types.BLOB);
     registerColumnType("varbinary", Types.BLOB);
     registerColumnType("bytea", Types.BLOB);
     registerColumnType("raw", Types.BLOB);
     registerColumnType("boolean", Types.BOOLEAN);
     registerColumnType("char", Types.CHAR);
        registerColumnType("varchar", Types.VARCHAR);
        registerColumnType("date", Types.DATE);
        registerColumnType("timestamp", Types.TIMESTAMP);
        registerColumnType("timestamp with timezone", Types.TIMESTAMP);
        registerColumnType("datetime", Types.TIMESTAMP);
        registerColumnType("smalldatetime", Types.TIMESTAMP);
        registerColumnType("double precision", Types.DOUBLE);
        registerColumnType("float", Types.FLOAT);
        registerColumnType("float8", Types.FLOAT);
        registerColumnType("real", Types.DOUBLE);        
        registerColumnType("bigint", Types.BIGINT);
        registerColumnType("smallint", Types.SMALLINT);
        registerColumnType("integer", Types.INTEGER);
        registerColumnType("int", Types.INTEGER);
        registerColumnType("tinyint", Types.INTEGER);
        registerColumnType("int8", Types.INTEGER);
        registerColumnType("decimal", Types.INTEGER);                
        registerColumnType("numeric", Types.NUMERIC);
        registerColumnType("number", Types.NUMERIC);
        registerColumnType("money", Types.NUMERIC);
        registerColumnType("time", Types.TIME);
        registerColumnType("time with timezone", Types.TIME);   
        registerColumnType("interval", Types.TIME);

    public String getCurrentDate() throws DialectException {
        return "current_date";
    public String getCurrentTimestamp() throws DialectException {
     return "current_timestamp";
    public String getCurrentTime() throws DialectException {
     return "current_time";

    public String getCurrentDateSelect() {
        return "select current_date";

    public String getRecycleBinTablePrefix() {
        return null;

    public String getCursorSqlTypeName() {
        return ProcUtil.REF_CURSOR;

    public int getCursorSqlType() {
        return Types.OTHER;

    public String getSqlChecker() {
        return "select 1";
4. You must register the dialect in NextReports. To make this happen in designer and server you have to add some java VM parameters. (nextreports.vmoptions  file from designer and start-nextserver.vmoptions from server)
-Dnext.dialect.database_1="Vertica Database" 

First parameter must be the name taken from DataBaseMetaData.getDatabaseProductName().

If you need to register more dialects, you use different suffix indexes.