Results 1 to 2 of 2
  1. #1
    hitesh is offline Member
    Join Date
    Jul 2010
    Posts
    28
    Rep Power
    0

    Smile reporting with ireport

    Hi
    I create a report with iReport-3.7.6. Now I m trying to call a report file(.jrxml) from java.

    My code is as follows-

    Java Code:
    import java.sql.*;
    import net.sf.jasperreports.view.JasperViewer;
    import net.sf.jasperreports.engine.xml.JRXmlLoader;
    import net.sf.jasperreports.engine.JasperCompileManager;
    import net.sf.jasperreports.engine.JasperFillManager;
    import net.sf.jasperreports.engine.JasperPrint;
    import net.sf.jasperreports.engine.design.JasperDesign;
    import net.sf.jasperreports.engine.JasperReport;
    import java.io.OutputStream;
    
    
    
    public class ReportDriver
                {
                    public ReportDriver() {}
        
       		public static Connection connectDB(String databaseName, String userName, String password) 
    			{
            			Connection jdbcConnection = null;
            			try{
                				Class.forName("com.mysql.jdbc.Driver");
                				jdbcConnection = DriverManager.getConnection(databaseName,userName,password);
            	   		   }
    				catch(Exception ex)
    		   		   {
               				 String connectMsg = "Could not connect to the database: " + ex.getMessage() + " " + ex.getLocalizedMessage();
                		 		System.out.println(connectMsg);
            	   		   }
            			return jdbcConnection;
        	    		}
        
    
    		public static void runReport(String databaseName, String userName, String password,String reportFile) 
    			{
          				try{
             				JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
    					JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
             				Connection jdbcConnection = connectDB(databaseName, userName, password);
             				JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, jdbcConnection);
             				JasperViewer.viewReport(jasperPrint);
          				    }
    				catch(Exception ex) {
             				String connectMsg = "Could not create the report " + ex.getMessage() + " " + ex.getLocalizedMessage();
            				 System.out.println(connectMsg);
          				     }
       	     		}
        
    
        	public static void main(String[] args) 
    	     {
            	if (args.length == 4) 
    			{
                			String databaseName = args[0] ;
            	 		String userName = args[1];
             			String password = args[2];
             			String reportFile = args[3];
                			runReport(databaseName, userName, password, reportFile);
           	     		}
    		else
    			{
                			System.out.println("Usage:");
                			System.out.println("java ReportDriver databaseName userName password reportFileLocation");
            		}
            			return;
            
        	     }
    	}




    The libraries are-

    commons-beanutils-1.5.jar
    commons-collections-2.1.1.jar
    commons-digester-1.7.jar
    commons-logging-1.0.2.jar
    jasperreports-1.2.0.jar
    mysql-connector-java-5.1.6-bin.jar

    I compile the above code from a batch file as follows-

    javac -classpath .;javaLib\mysql-connector-java-5.1.6-bin.jar;javaLib\jasperreports-1.2.0.jar ReportDriver.java
    pause

    And run the code with a another batch file as follows-

    java -cp .;javaLib\classes12.jar;javaLib\jasperreports-1.2.0.jar;javaLib\commons-digester-1.7.jar;javaLib\commons-collections-2.1.jar;javaLib\commons-logging-1.0.2.jar;javaLib\commons-beanutils-1.5.jar ReportDriver abc root xyz test.jrxml
    pause

    The code is compiled well.
    But when I run that code the following errors are generated-

    C:\Users\hitesh.hitesh-PC\Desktop\test>java -cp .;javaLib\classes12.jar;javaLib\
    jasperreports-1.2.0.jar;javaLib\commons-digester-1.7.jar;javaLib\commons-collect
    ions-2.1.jar;javaLib\commons-logging-1.0.2.jar;javaLib\commons-beanutils-1.5.jar
    ReportDriver bhabani root baishya965 test.jrxml
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/co
    llections/ArrayStack
    at org.apache.commons.digester.Digester.<init>(Digest er.java:138)
    at net.sf.jasperreports.engine.xml.JRXmlDigester.<ini t>(JRXmlDigester.ja
    va:62)
    at net.sf.jasperreports.engine.xml.JRXmlDigesterFacto ry.createDigester(J
    RXmlDigesterFactory.java:790)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(J RXmlLoader.java:202
    )
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(J RXmlLoader.java:167
    )
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(J RXmlLoader.java:151
    )
    at ReportDriver.runReport(ReportDriver.java:36)
    at ReportDriver.main(ReportDriver.java:57)

    C:\Users\hitesh.hitesh-PC\Desktop\test>pause
    Press any key to continue . . .



    Can anybody help me?????????????

    I found the code and all the instructions in the following link
    Step by Step Instructions on How to Run a Jasper Report from Java

  2. #2
    demonick is offline Member
    Join Date
    Dec 2010
    Posts
    27
    Rep Power
    0

    Default

    The problem is missing .jar files, try adding some more, even if they logically don't belong there.

Similar Threads

  1. Java Reporting Tools
    By j3grewal in forum Advanced Java
    Replies: 0
    Last Post: 11-18-2010, 07:43 PM
  2. reporting ssystem
    By erik80 in forum JDBC
    Replies: 1
    Last Post: 10-01-2010, 11:36 AM
  3. Newbie reporting
    By nelsaez in forum Introductions
    Replies: 0
    Last Post: 11-05-2007, 07:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •