0

I want to use vertx and JasperReports, I create my connection and I test it, everything is ok, but when I want to fill jasper report by using fillReport method (where the last one is Connection) it shows error :

The method fillReport(JasperReport, Map< String,Object >, Connection) in the type JasperFillManager is not applicable for the arguments (JasperReport, null, Class < connection>).

Any idea how should I cast my SQLConnect to connect ?

Here is my code :

   AsyncSQLClient client = MySQLClient.createShared(vertx, mySQLClientConfig);
   client.getConnection(res -> {
         if (res.succeeded()) {
                  SQLConnection connection = res.result();
                  try{
              String report = "C:\\Users\\paths\\Test1.jrxml";
              JasperReport Jasp = JasperCompileManager.compileReport(report);
              JasperPrint JASP_PRINT = JasperFillManager.fillReport(Jasp, null, connection);
              JasperViewer.viewReport(JASP_PRINT);                          
                      }
                  catch(Exception ex){System.out.println(ex);}

Regards.

zackzulg
  • 599
  • 2
  • 5
  • 21

1 Answers1

2

The answer is simple. You can't cast a Vert.x io.vertx.ext.sql.SQLConnection to a JDBC java.sql.Connection.

Vert.x heavily relies upon asynchronous calls. JDBC is blocking and so Vert.x wraps it with an asynchronous interface (and a bit more). There is no way to get to the real java.sql.Connection as there is no getter or something like that in the JDBCConnectionImpl or in the SQLConnection interface.

That doesn't mean you can't use Jasper with Vert.x. You need to open you own JDBC connection – but don't block the Event loop! So I suggest you have a look at the Worker Verticles, which don't block the Event loop because they spin up a separat thread.

alexvetter
  • 1,998
  • 2
  • 16
  • 42