Jump to content
We've recently updated our Privacy Statement, available here ×

Setup Java application for jasper report


bhavinb73

Recommended Posts

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.

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

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);    }}[/code]

 

Link to comment
Share on other sites

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).

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...