问题
I'am currently following a tutorial ( http://kristantohans.wordpress.com/2010/03/01/new-to-jasperreport-build-your-first-impressive-application-part-2/ ) and he use a java db connection (conn)
50 try {
51 //Fill the report with parameter, connection and the stream reader
52 JasperPrint jp = JasperFillManager.fillReport(is, null, conn);
How can i do to connect to mongo here ? Because with mongo i have :
Mongo m = new Mongo( "localhost" , 27017 );
DB db = m.getDB( "test" );
and
JasperPrint jp = JasperFillManager.fillReport(is, null, m);
doesn't work
Thanks !
回答1:
You can't use Jasper Reports with MongoDB as its data provider directly, because MongoDB's driver is not JDBC compatible.
You can fetch your data from MongoDB and wrap it into an JRDataSource, there are some available implementations of JRDataSourche such as JRBeanArrayDataSource and JRBeanCollectionDataSource.
For more information about JRDataSource and implementations visit http://jasperreports.sourceforge.net/api/index.html
来源:https://stackoverflow.com/questions/9327718/jasperfillmanager-fillreport-and-mongo