0

我想使用 vertx 和 JasperReports,创建连接并对其进行测试,一切正常,但是当我想使用 fillReport 方法(最后一个是连接)填充 jasper 报告时,它显示错误:

JasperFillManager 类型中的方法 fillReport(JasperReport, Map< String,Object >, Connection) 不适用于参数(JasperReport, null, Class < connection>)。

知道我应该如何将我的 SQLConnect 转换为连接吗?

这是我的代码:

   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);}

问候。

4

1 回答 1

1

答案很简单。您不能将 Vert.xio.vertx.ext.sql.SQLConnection转换为 JDBC java.sql.Connection

Vert.x 严重依赖异步调用。JDBC 是阻塞的,因此 Vert.x 使用异步接口(以及更多)包装它。没有办法接近真实的东西,因为接口或接口java.sql.Connection中没有 getter 或类似的东西。JDBCConnectionImplSQLConnection

这并不意味着您不能将 Jasper 与 Vert.x 一起使用。您需要打开自己的 JDBC 连接——但不要阻塞事件循环!所以我建议你看看Worker Verticles,它不会阻塞事件循环,因为它们会启动一个单独的线程。

于 2016-04-22T07:57:59.810 回答