8 Replies Latest reply on May 13, 2008 11:26 AM by 807601

    JasperReport date parameter problem

    807599
      Hi there!

      I have a problem of passing parameter in jasper from java of type date. If I pass the parameter it gives me blank jasper report viewer with JOptionPane stating my query didnt return anything, but there is result for that returned query.

      here my snipnet .jrxml file
      parameter name="first_date" isForPrompting="false" class="java.lang.String">
                <parameterDescription><![CDATA[first date]]></parameterDescription>
           </parameter>
           <parameter name="last_date" isForPrompting="false" class="java.lang.String">
                <parameterDescription><![CDATA[last date]]></parameterDescription>
           </parameter>
           <parameter name="currency_type" isForPrompting="false" class="java.lang.String">
                <parameterDescription><![CDATA[currency type]]></parameterDescription>
           </parameter>
           <queryString><![CDATA[select a.card_number,a.transaction_local_date,m.company_name,a.trace_audit_number,a.transaction_fee,a.transaction_amount,a.transaction_currency
      from autho_activity a,ptserv p,merchant m
      where a.card_acceptor_id = p.outlet_number and p.merchant_number = m.merchant_number and to_date(a.transaction_local_date) between TO_DATE($P{first_date}) and TO_DATE($P{last_date}) and a.transaction_currency = $P{currency_type}
      and a.acquirer_bank='983411']]></queryString>
      
           <field name="CARD_NUMBER" class="java.lang.String"/>
           <field name="TRANSACTION_LOCAL_DATE" class="java.sql.Timestamp"/>
           <field name="COMPANY_NAME" class="java.lang.String"/>
           <field name="TRACE_AUDIT_NUMBER" class="java.lang.String"/>
           <field name="TRANSACTION_FEE" class="java.math.BigDecimal"/>
           <field name="TRANSACTION_AMOUNT" class="java.math.BigDecimal"/>
           <field name="TRANSACTION_CURRENCY" class="java.lang.String"/>
      and this is the java code
      Date d1=null,d2=null;
            String result1="",result2="";
            SimpleDateFormat df=new SimpleDateFormat("dd MMM yyyy");
            
            Map<String, Object> params = new HashMap<String, Object>();
            
            try {
            d1=df.parse("1 april 2007");
            result1=df.format(d1);
            
            d2=df.parse("10 april 2007");
            result2=df.format(d2);
            
            } catch (ParseException ex) {
            ex.printStackTrace();
            }
            
            params.put("start_date",result1);
            params.put("last_date", result2);
            params.put("currency_type","834");
            
            try {
            JasperReport jasperReport =
              JasperCompileManager.compileReport(reportSource);
            
            // Make the driver class available.
            Class.forName("oracle.jdbc.driver.OracleDriver");
            
            // Create a connection to pass into the report.
            java.sql.Connection conn = DriverManager.getConnection(
              "jdbc:oracle:thin:@ip:1521:SID","u","p");
            // Replace the empty JR datasource parameter with
            // the connection parameter named conn.
            JasperPrint jasperPrint =
              JasperFillManager.fillReport(
              jasperReport, params, conn);
            
            //JasperExportManager.exportReportToHtmlFile(
            //       jasperPrint, reportDest);
            JasperViewer jasperViewer= new JasperViewer(jasperPrint,false);
            //jasperViewer.viewReport(jasperPrint);
            //jasperViewer.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
            jasperViewer.setVisible(true);
      I need any other kind of idea of passing date..

      my database is oracle