Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. Exception in thread "main" java.lang.Error: Unresolved compilation problems:
  2.  
  3. type cannot be resolved
  4.  
  5. CenteredStyle cannot be resolved to a variable
  6. type cannot be resolved
  7.  
  8. boldStyle cannot be resolved to a variable
  9. type cannot be resolved
  10.  
  11. CenteredStyle cannot be resolved to a variable
  12. type cannot be resolved
  13.  
  14. CenteredStyle cannot be resolved to a variable
  15. type cannot be resolved
  16.  
  17. CenteredStyle cannot be resolved to a variable
  18.  
  19. BigDecimal cannot be resolved to a type
  20. CenteredStyle cannot be resolved to a variable
  21.  
  22. at project.Reports.main(Reports.java:36)
  23.  
  24. package project;
  25.  
  26. import java.io.FileNotFoundException;
  27. import java.io.FileOutputStream;
  28. import java.sql.Connection;
  29. import java.sql.DriverManager;
  30. import java.sql.SQLException;
  31.  
  32. import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
  33. import net.sf.dynamicreports.report.builder.DynamicReports;
  34. import net.sf.dynamicreports.report.builder.column.Columns;
  35. import net.sf.dynamicreports.report.builder.column.TextColumnBuilder;
  36. import net.sf.dynamicreports.report.builder.component.Components;
  37. import net.sf.dynamicreports.report.builder.datatype.DataTypes;
  38. import net.sf.dynamicreports.report.constant.HorizontalAlignment;
  39. import net.sf.dynamicreports.report.exception.DRException;
  40. import net.sf.dynamicreports.report.builder.style.StyleBuilder;
  41. import net.sf.dynamicreports.report.builder.datatype.BigDecimalType;
  42. import net.sf.dynamicreports.report.builder.group.ColumnGroupBuilder;
  43.  
  44. public class Reports {
  45.  
  46. public static void main(String[] args) {
  47. Connection connection = null;
  48. try {
  49. Class.forName("com.mysql.jdbc.Driver");
  50. connection = DriverManager.getConnection("jdbc:mysql://hostname:3306/Project","root", "codingdevil");
  51. } catch (SQLException e) {
  52. e.printStackTrace();
  53. return;
  54. } catch (ClassNotFoundException e) {
  55. e.printStackTrace();
  56. return;
  57. }
  58.  
  59. JasperReportBuilder report = DynamicReports.report();
  60. Columns col;
  61. TextColumnBuilder<Integer> rowNumberColumn = Columns.reportRowNumberColumn("No.");
  62. TextColumnBuilder<java.util.Date> columndate = col.column("Date", "Date_Of_Sale", type.dateType()).setStyle(CenteredStyle);
  63. TextColumnBuilder<String> columnItem = col.column("Item Name", "Item_Name", type.stringType()).setStyle(boldStyle);
  64. TextColumnBuilder<String> columnCustomer = col.column("Customer Name", "Customer_name", type.stringType()).setStyle(CenteredStyle);
  65. TextColumnBuilder<Double> columnunit = col.column("Unit Price", "Item_Price", type.doubleType()).setStyle(CenteredStyle);
  66. TextColumnBuilder<Integer> columnqty = col.column("Qty", "Item_qty", type.integerType()).setStyle(CenteredStyle);
  67. TextColumnBuilder<BigDecimal> columnsub = columnqty.multiply(columnunit).setTitle("Subtotal").setStyle(CenteredStyle);
  68. report
  69. .columns(
  70. rowNumberColumn,columnItem,columnCustomer,columndate,columnunit,columnqty,columnsub
  71. )
  72. .title(//title of the report
  73. Components.text("SimpleReportExample")
  74. .setHorizontalAlignment(HorizontalAlignment.CENTER))
  75. .pageFooter(Components.pageXofY())//show page number on the page footer
  76. .setDataSource("SELECT * FROM Holidays",connection);
  77.  
  78. try {
  79. //show the report
  80. report.show();
  81.  
  82. //export the report to a pdf file
  83. report.toPdf(new FileOutputStream("c:/report.pdf"));
  84. } catch (DRException e) {
  85. e.printStackTrace();
  86. } catch (FileNotFoundException e) {
  87. e.printStackTrace();
  88. }
  89. }
  90. }
  91.  
  92. <dependencies>
  93. <!-- DynamicReports -->
  94. <dependency>
  95. <groupId>net.sourceforge.dynamicreports</groupId>
  96. <artifactId>dynamicreports-core</artifactId>
  97. <version>3.1.3</version>
  98. </dependency>
  99.  
  100. <!-- MySQL database driver -->
  101. <dependency>
  102. <groupId>mysql</groupId>
  103. <artifactId>mysql-connector-java</artifactId>
  104. <version>5.1.25</version>
  105. </dependency>
  106. </dependencies>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement