如何使用jasper Report使用某些mysql数据库打印jLabel值

时间:2018-06-23 07:38:59

标签: java jasper-reports

我创建了一个jDialog,其中包含一个表,3个jLabel和一个打印按钮。 当我单击那些按钮时,将打开一个jasper报告,该报告填充了一些mysql数据。它工作正常,但问题是我还想在没有mysql数据的jasper报告中显示3个jLabes数据。

我是CSE的学生,请帮我怎么可能?

这是我的打印按钮代码

// Report Display
        this.dispose();
        try {
            //String report="F:\\My Practice\\Programming\\java\\DCM\\src\\dcm\\report.jrxml";
            JasperDesign jd = JRXmlLoader.load("E:\\Java\\HBD-DHPM\\src\\Accounting\\cashBook.jrxml");
            String sql2 = "SELECT\n"
                    + "     active_organization.`slno` AS active_organization_slno,\n"
                    + "     active_organization.`id` AS active_organization_id,\n"
                    + "     active_organization.`name` AS active_organization_name,\n"
                    + "     active_organization.`address` AS active_organization_address,\n"
                    + "     active_organization.`phone` AS active_organization_phone,\n"
                    + "     active_organization.`start_date` AS active_organization_start_date,\n"
                    + "     active_organization.`exp_date` AS active_organization_exp_date,\n"
                    + "     acc_ledger.`lgr_id` AS acc_ledger_lgr_id,\n"
                    + "     acc_ledger.`group_name` AS acc_ledger_group_name,\n"
                    + "     acc_ledger.`ledger_name` AS acc_ledger_ledger_name,\n"
                    + "     acc_ledger.`particular` AS acc_ledger_particular,\n"
                    + "     acc_ledger.`trans_no` AS acc_ledger_trans_no,\n"
                    + "     acc_ledger.`debit_amount` AS acc_ledger_debit_amount,\n"
                    + "     acc_ledger.`credit_amount` AS acc_ledger_credit_amount,\n"
                    + "     acc_ledger.`balance_amount` AS acc_ledger_balance_amount,\n"
                    + "     acc_ledger.`emp_id` AS acc_ledger_emp_id,\n"
                    + "     acc_ledger.`date_time` AS acc_ledger_date_time\n"
                    + "FROM\n"
                    + "     `active_organization` active_organization,\n"
                    + "     `acc_ledger` acc_ledger WHERE acc_ledger.`ledger_name`='Cash' AND (acc_ledger.`date_time` BETWEEN '" + txt_date_from.getText() + "' AND '" + txt_date_to.getText() + "') ORDER BY lgr_id DESC";

            JRDesignQuery newQuery = new JRDesignQuery();
            newQuery.setText(sql2);
            jd.setQuery(newQuery);
            JasperReport jr = JasperCompileManager.compileReport(jd);
            JasperPrint jp = JasperFillManager.fillReport(jr, null, conn);
            JasperViewer.viewReport(jp, false);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }`

0 个答案:

没有答案