1

我目前正在学习一个教程(http://kristantohans.wordpress.com/2010/03/01/new-to-jasperreport-build-your-first-impressive-application-part-2/),他使用一个java数据库连接 (conn)

50          try {
51       //Fill the report with parameter, connection and the stream reader    
52              JasperPrint jp = JasperFillManager.fillReport(is, null, conn);

我怎样才能在这里连接到 mongo ?因为有了 mongo 我有:

Mongo m = new Mongo( "localhost" , 27017 );
DB db = m.getDB( "test" );

JasperPrint jp = JasperFillManager.fillReport(is, null, m);

不工作

谢谢 !

4

1 回答 1

1

您不能直接将 Jasper Reports 与 MongoDB 作为其数据提供者一起使用,因为 MongoDB 的驱动程序不兼容 JDBC。

您可以从 MongoDB 中获取数据并将其包装到 JRDataSource 中,JRDataSourche 有一些可用的实现,例如 JRBeanArrayDataSource 和 JRBeanCollectionDataSource。

有关 JRDataSource 和实现的更多信息,请访问http://jasperreports.sourceforge.net/api/index.html

于 2012-02-17T12:03:09.483 回答