2015-09-28 25 views
0

JRBeanCollectionDataSource在碧玉如何使用

try { 
    //Connecting to the MySQL database 

    Class.forName("com.mysql.jdbc.Driver"); 
    conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/hospital", "root" ,"root"); 

    String report="C:\\Users\\DELL\\report10.jrxml"; 

    JasperReport jasperreport=JasperCompileManager.compileReport(report); 
    patientDB DataBeanList = new patientDB(); 

    ArrayList<patientBean> dataList = DataBeanList.getDataBeanList(); 

    JRBeanCollectionDataSource beanColDataSource = 
    new JRBeanCollectionDataSource(dataList); 
    Map<String,Object> parameters = new HashMap<String,Object>(); 

    JasperPrint jp=JasperFillManager.fillReport(jasperreport, parameters,beanColDataSource); 
    JasperViewer.viewReport(jp); 

} 
catch(Exception e) 
{ 
    out.println(e); 
} 

我在碧玉報告新試圖從bean類,但沒有價值發生,我花我的最後7天爲這個

回答

0

請澄清,

你得到的錯誤是什麼?

DataBeanList.getDataBeanList()是否返回帶有值的對象?

Db連接配置是否正確?

jrxml的路徑是否正確?(我認爲你不需要路徑中的雙斜槓)