0

我是碧玉报告的新手。我已经使用 iReport 3.5.2 成功创建了报告,在 iReport 中,日期类型为 java.sql.Timestamp 并将日期输入为(Wed 12/06/2013)我使用 Eclipse IDE 并在 servlet 代码中格式化日期,但 Timestamp值即将到来(2013-06-12 00:00:00.000),它正在显示空的碧玉报告。我正在使用以下罐子:-

commons-beanutils-1.5.jar
commons-collections-2.1.jar
commons-digester-1.7.jar
commons-logging-1.0.2.jar
commons-logging-api-1.0.2.jar
groovy-all-1.5.5.jar
itext-2.1.5.jar jasperreports
-3.5.2.jar
jdt-compiler.jar
jfreechart-1.0.0-rc1.jar
jtds-1.2.jar

请找到下面的 servlet 代码,请帮助我显示带有数据的报告。

公共字符串 generateReport(HttpServletRequest 请求,HttpServletResponse 响应)

{
    try
    {
        Connection connection = null;
        JasperReport jasperReport = null;
        JasperPrint jasperPrint=null;
        Date today = null;
        Timestamp date = null;
        String dateString = "";

        connection = EmployeeJDBCUtil.getConnection();
        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE dd/MM/yyyy);
        try {
            dateString = dateFormat.format(new Date());
            today = dateFormat.parse(dateString);
            Timestamp ts = new Timestamp(today.getTime());

        } catch (ParseException e1) {
            e1.printStackTrace();
        }
        Map parameters = new HashMap();
        parameters.put("Date", ts );

       String report_File = "D:/timesheet/EmployeeTimeSheet/WebContent/TimeSheet2.jrxml";
       File report_FileName = new File(report_File);
       if(report_FileName.exists())
       {
           try {

                    JasperDesign jasperDesign = JRXmlLoader.load(report_File);
                    jasperReport = JasperCompileManager.compileReport(jasperDesign);

                    jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,connection);
                    JasperExportManager.exportReportToPdfFile(jasperPrint, "D:/sample.pdf");
                    JasperViewer.viewReport(jasperPrint);

        } catch (Exception e) {
            e.printStackTrace();
        }
   }
      } catch (FileNotFoundException e) {
          e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } 
    finally
    {
        if(connection != null)
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
    }
    return "index.jsp";
}
4

0 回答 0