Setup Java application for jasper report

0

Hello,

I have already created .JRXML file using oracle as datasource, using Jasper studio 6.6.

How can I use that file in my existing Springboot application so that I can add connection paramater, report parameter and display report to user in a seperate browser window.

 

Thanks in advance.

 

bhavinb73's picture
Joined: Jun 22 2018 - 5:44am
Last seen: 3 years 2 weeks ago
Am not sure how can I respond to an "answer" given by user "reportdev". So please excuse me for that. User "reportdev" thank you for your quick response, really appreciate it. But, it seems like this is for a desktop application. There would be some ways to show the JFrame on a webpage, but am thinking taking JFrame on web page would not be best, although it might work. So, am still looking for a solution to show jasper report output (as a PDF or HTML) within web application (it can open another instance of browser or prompt user to save PDF file).
bhavinb73 - 3 years 3 months ago

there are so many community posts, which can guide you through exporting the jasperprint to a browser. 

please check those. https://community.liferay.com/forums/-/message_boards/message/10540696

reportdev - 3 years 3 months ago

1 Answer:

0

I'm using JFrame here, but you can change it to something else. 

    public static void main(String[] args) throws ParseException, SQLException, JRException {
 
        Connection con = DriverManager.getConnection("jdbc:oracle", "user","password");
 
        java.sql.Date sqlDate = new java.sql.Date((new SimpleDateFormat("MM/dd/yyyy").parse("07/01/2018")).getTime());
 
        Map parameters = new HashMap();
        Map<String, String> temp = new HashMap<String, String>();
        parameters.put("paramName", sqlDate); 
        String workingDir = System.getProperty("user.dir");
        String file = workingDir + "\\src\\resources\\main_jrxml.jasper"; 
        System.out.println("Current working directory : " + file);
 
        JasperReport report = (JasperReport) JRLoader.loadObjectFromFile(file);
        JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, con);
 
        JFrame frame = new JFrame("Report");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new JRViewer(jasperPrint));
        frame.pack();
        frame.setVisible(true);
    }
}

reportdev's picture
1330
Joined: Oct 12 2015 - 12:05pm
Last seen: 1 day 11 hours ago
Feedback
randomness