2001 JI Open Discussion Posted August 15, 2006 Share Posted August 15, 2006 By: ali abd - yadh Display a ResultSet 2002-08-26 19:38Hi , I am trying to integrate jasperReport to my application which interacts with Mysql database. I am thinking of running a query and display the resultset as report. I do understand that I need to specify an xml file for the report design view. I am not sure what exactly I need to do once I have a resultset returned from a query execution. I went through the tutorial and I still not sure how to take a resultset and lunch the viewer to display it. I am hoping that you can provide us with a small example, which performs this operation. By the way I was able to run all samples that comes with the download but it needs ant to build them and to run them. I am trying to have an example that runs without any use of ant. A perfect example would be reading a table from the database and dumping the whole table in the viewer. I think this will help a lot of people in getting the feel of jasperReport capabilities Thank you in advance By: Teodor Danciu - teodord RE: Display a ResultSet 2002-08-27 02:02 Hi, There are at least 3 steps you have to consider: 1) Create your XML report design and compile it. You will obtain a .jasper file, containing the report template. 2) Fill the report template with data from a data source (including ResultSet objects). You will obtain a .jrprint file with the generated report. 3) View the .jrprint file using the built-in JasperViewer or transform it into PDF. Your question concerns the step 2). How to fill a report from a ResultSet? If you have the ResultSet object already, all you have to do is to use one of the methods exposed by the JasperFillManager that receive a JRDataSource object as a parameter. You'll use the JRResultSetDataSource class to wrap your ResultSet object into a JRDataSource instance. There is another way to fill reports from a database. You can put the SQL query directly into the XML report design and when filling the report you supply a java.sql.Connection object instead of a JRDataSource object. This is shown in the "jasper", "scriptlet" or "subreport" samples. You can give up using ANT anytime you want. It only helps you run the samples effortlessly. You can run them by launching the JVM yourself from the command line making sure you set the classpath and the required system properties correctly. The code in those samples applications does not change even if you don't use ANT. I think you can find all there is to know about how to use JasperReports in those sample applications. Good luck! Teodor Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now