java - Jasper Dynamic Reports - using jasper reports to generate a report getting errors -
i want generate report database. working on jasper reporting tool , i'm getting following errors:
exception in thread "main" java.lang.error: unresolved compilation problems: type cannot resolved centeredstyle cannot resolved variable type cannot resolved boldstyle cannot resolved variable type cannot resolved centeredstyle cannot resolved variable type cannot resolved centeredstyle cannot resolved variable type cannot resolved centeredstyle cannot resolved variable bigdecimal cannot resolved type centeredstyle cannot resolved variable @ project.reports.main(reports.java:36)
code:
package project; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.sql.connection; import java.sql.drivermanager; import java.sql.sqlexception; import net.sf.dynamicreports.jasper.builder.jasperreportbuilder; import net.sf.dynamicreports.report.builder.dynamicreports; import net.sf.dynamicreports.report.builder.column.columns; import net.sf.dynamicreports.report.builder.column.textcolumnbuilder; import net.sf.dynamicreports.report.builder.component.components; import net.sf.dynamicreports.report.builder.datatype.datatypes; import net.sf.dynamicreports.report.constant.horizontalalignment; import net.sf.dynamicreports.report.exception.drexception; import net.sf.dynamicreports.report.builder.style.stylebuilder; import net.sf.dynamicreports.report.builder.datatype.bigdecimaltype; import net.sf.dynamicreports.report.builder.group.columngroupbuilder; public class reports { public static void main(string[] args) { connection connection = null; try { class.forname("com.mysql.jdbc.driver"); connection = drivermanager.getconnection("jdbc:mysql://hostname:3306/project","root", "codingdevil"); } catch (sqlexception e) { e.printstacktrace(); return; } catch (classnotfoundexception e) { e.printstacktrace(); return; } jasperreportbuilder report = dynamicreports.report(); columns col; textcolumnbuilder<integer> rownumbercolumn = columns.reportrownumbercolumn("no."); textcolumnbuilder<java.util.date> columndate = col.column("date", "date_of_sale", type.datetype()).setstyle(centeredstyle); textcolumnbuilder<string> columnitem = col.column("item name", "item_name", type.stringtype()).setstyle(boldstyle); textcolumnbuilder<string> columncustomer = col.column("customer name", "customer_name", type.stringtype()).setstyle(centeredstyle); textcolumnbuilder<double> columnunit = col.column("unit price", "item_price", type.doubletype()).setstyle(centeredstyle); textcolumnbuilder<integer> columnqty = col.column("qty", "item_qty", type.integertype()).setstyle(centeredstyle); textcolumnbuilder<bigdecimal> columnsub = columnqty.multiply(columnunit).settitle("subtotal").setstyle(centeredstyle); report .columns( rownumbercolumn,columnitem,columncustomer,columndate,columnunit,columnqty,columnsub ) .title(//title of report components.text("simplereportexample") .sethorizontalalignment(horizontalalignment.center)) .pagefooter(components.pagexofy())//show page number on page footer .setdatasource("select * holidays",connection); try { //show report report.show(); //export report pdf file report.topdf(new fileoutputstream("c:/report.pdf")); } catch (drexception e) { e.printstacktrace(); } catch (filenotfoundexception e) { e.printstacktrace(); } } }
it seems project missing jars, , cannot understand meanings of these words, try check if have jar files need.
try use maven such in example.
add these dependencies pom.xml
<dependencies> <!-- dynamicreports --> <dependency> <groupid>net.sourceforge.dynamicreports</groupid> <artifactid>dynamicreports-core</artifactid> <version>3.1.3</version> </dependency> <!-- mysql database driver --> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.25</version> </dependency> </dependencies>
Comments
Post a Comment