Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Exception in thread "main" java.lang.Error: Unresolved compilation problems:
- type cannot be resolved
- CenteredStyle cannot be resolved to a variable
- type cannot be resolved
- boldStyle cannot be resolved to a variable
- type cannot be resolved
- CenteredStyle cannot be resolved to a variable
- type cannot be resolved
- CenteredStyle cannot be resolved to a variable
- type cannot be resolved
- CenteredStyle cannot be resolved to a variable
- BigDecimal cannot be resolved to a type
- CenteredStyle cannot be resolved to a variable
- at project.Reports.main(Reports.java:36)
- 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 the report
- Components.text("SimpleReportExample")
- .setHorizontalAlignment(HorizontalAlignment.CENTER))
- .pageFooter(Components.pageXofY())//show page number on the page footer
- .setDataSource("SELECT * FROM Holidays",connection);
- try {
- //show the report
- report.show();
- //export the report to a pdf file
- report.toPdf(new FileOutputStream("c:/report.pdf"));
- } catch (DRException e) {
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
- <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>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement