Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Petr

Thread: Java Reports

  1. #1
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Unhappy Java Reports

    Hello to all... I am doing a college project and i want to connect java with oracle reports or any other to take out the reports... I already made report but dont know how to call from java... Please share any idea.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Hi. Do you have strong require about using Oracle Report? More widely solve to use Jasper Report or Birt Report. I prefer Birt Report.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    Thank you v much. I asked this question on several forums , mostly on Daniweb but they all are idiots havnt answered a single question to the point. Your reply is thousand times useful for me. I am going to give it a try.

  4. #4
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    How can i call A report made in Birt from JAVA SE application?

  5. #5
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    yes of course. see that java - birt in a desktop application - Stack Overflow
    The Eclipse has special build for create birt report. You can use it.
    Skype: petrarsentev
    http://TrackStudio.com

  6. #6
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    Java Code:
    //----------- Code for Test Class ---------------------------
    import java.io.IOException;
    import org.eclipse.birt.report.engine.api.EngineConfig;
    import org.eclipse.birt.report.model.api.DataSetHandle;
    import org.eclipse.birt.report.model.api.DesignElementHandle;
    import org.eclipse.birt.report.model.api.DesignEngine;
    import org.eclipse.birt.report.model.api.DesignFileException;
    import org.eclipse.birt.report.model.api.ElementFactory;
    import org.eclipse.birt.report.model.api.OdaDataSetHandle;
    import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
    import org.eclipse.birt.report.model.api.PropertyHandle;
    import org.eclipse.birt.report.model.api.ReportDesignHandle;
    import org.eclipse.birt.report.model.api.SessionHandle;
    import org.eclipse.birt.report.model.api.SlotHandle;
    import org.eclipse.birt.report.model.api.activity.SemanticException;
    import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
    
    public class test 
    {
    private PropertyHandle computedColumns = null;
    private SessionHandle sessionHandle;
    private ReportDesignHandle reportDesignHandle;
    private ElementFactory elementFactory;
    private DesignElementHandle designElementHandle;
    private OdaDataSourceHandle odaDataSourceHandle;
    private OdaDataSetHandle odaDataSetHandle;
    private EngineConfig engineConfig;
    
    private String reportFileName = null;
    private String dataSrc = null;
    private String dataSet = null;
    
    /*
     * Constructor saves away report design file name, data source and data set info
     * @param:
     * fileName: Name of report design file
     * dataSrc:  Name of data source
     * dataSet:  Name of data set
     */
    test (String fileName, String dataSrc, String dataSet)
    {
    	this.reportFileName = fileName;
    	this.dataSrc = dataSrc;
    	this.dataSet = dataSet;
    }
    
    /*
     * Initializes the variables
     */ 
    @SuppressWarnings("deprecation")
    public void Initialize ()
    {
    	// Setup config (assumes Eclipse installed in c:\eclipse
    	engineConfig = new EngineConfig( );
    	engineConfig.setEngineHome
    	                ("F:\\Birt Report\\workspace");
    
    	// Create a session handle. This is used to manage all open designs.
    	// Your app need create the session only once.
    	sessionHandle = DesignEngine.newSession(null);
    	
    	// Open a report design.
    	try {
    		reportDesignHandle = sessionHandle.openDesign(reportFileName);
    	} catch (DesignFileException e) {
    		e.printStackTrace();
    	}
    	
    	// The element factory creates instances of the various BIRT elements.
    	elementFactory = reportDesignHandle.getElementFactory();
    	
    	return;
    }
    
    /*
     * Connects to specified data source and data set
     */
    public void connectDS ()
    {
    	String tmp;
    	int ii;
    	
    	SlotHandle sloth = reportDesignHandle.getDataSources();
    	java.util.Iterator iter = sloth.iterator();
    		
    	// Search for specified data source
    	while (iter.hasNext() == true)
    	{
    		odaDataSourceHandle = (OdaDataSourceHandle) iter.next();
    		tmp = odaDataSourceHandle.getName();
    		if (tmp.compareTo(dataSrc) == 0)
    			break;
    	}
    		
    	// Search for specified data set
    	sloth = reportDesignHandle.getDataSets();
    	iter = sloth.iterator();
    	while (iter.hasNext() == true)
    	{
    		odaDataSetHandle = (OdaDataSetHandle) iter.next();
    		tmp = odaDataSetHandle.getName();
    		if (tmp.compareTo(dataSet) == 0)
    			break;
    	}
    
    	return;
    }
    
    /*
     * @param
     *  colName: Name of the computed column
     *  colExpr: Expression for the computed column 
     */
    public void addComputedColumn (String colName, String colExpr) 
         throws IOException, SemanticException
    {
    	// Create a computed column
    	ComputedColumn newColumn = new ComputedColumn();
    	newColumn.setName(colName);
    	newColumn.setExpression(colExpr);
    
    	computedColumns = 
    		odaDataSetHandle.getPropertyHandle (DataSetHandle.COMPUTED_COLUMNS_PROP);
    	computedColumns.addItem(newColumn);
    	
    	return;
    }
    
    /*
     * Saves the changes to a report design file
     */
    public void saveReport ()
    {
    	// Save the design and close it.
    	try {
    		reportDesignHandle.saveAs(reportFileName);
    	} catch (IOException e)	{
    		e.printStackTrace();
    	}
    	
    	reportDesignHandle.close ();
    	
    	return;
    }
    }
    Java Code:
    import java.io.IOException;
    import org.eclipse.birt.report.model.api.activity.SemanticException;
    
    public class main 
    {
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) 
    	{
    		test compCol = new test ("Company.rptdesign", "Data Source", "Company");
    		
    		compCol.Initialize();
    		compCol.connectDS();
    		
    		try {
    			compCol.addComputedColumn("CA", "if (row[\"State\"] == \"CA\") {row[\"CA\"] = 1;}");
    		} catch (SemanticException e) {
    			e.printStackTrace();
    		} catch (IOException e)	{
    			e.printStackTrace();
    		}
    		
    		compCol.saveReport();
    	}
    	
    
    }

    This is my code... I have downloaded birt made a simple Report according to data and use the code to connect but i m getting following error.

    Java Code:
    Jul 11, 2011 6:05:45 PM org.eclipse.birt.report.model.parser.ModuleReader readModule
    SEVERE: Parsed file was not found.
    Error.DesignFileException.SYNTAX_ERROR - 1 errors found! 
    1.)  org.eclipse.birt.report.model.parser.DesignParserException (code = Error.DesignParserException.FILE_NOT_FOUND, message : The file "Company.rptdesign" is not found.)	at java.io.FileInputStream(null:-2)
    	at java.io.FileInputStream(null:-1)
    	at java.io.FileInputStream(null:-1)
    	at sun.net.www.protocol.file.FileURLConnection(null:-1)
    	at sun.net.www.protocol.file.FileURLConnection(null:-1)
    	at java.net.URL(null:-1)
    	at org.eclipse.birt.report.model.parser.ModuleReader(ModuleReader.java:207)
    	at org.eclipse.birt.report.model.parser.DesignReader(DesignReader.java:143)
    	at org.eclipse.birt.report.model.core.DesignSessionImpl(DesignSessionImpl.java:242)
    	at org.eclipse.birt.report.model.core.DesignSessionImpl(DesignSessionImpl.java:218)
    	at org.eclipse.birt.report.model.api.SessionHandleImpl(SessionHandleImpl.java:224)
    	at test(test.java:63)
    	at main(main.java:13)
    
    
    	at org.eclipse.birt.report.model.parser.ModuleReader.readModule(ModuleReader.java:221)
    	at org.eclipse.birt.report.model.parser.DesignReader.read(DesignReader.java:143)
    	at org.eclipse.birt.report.model.core.DesignSessionImpl.openDesign(DesignSessionImpl.java:242)
    	at org.eclipse.birt.report.model.core.DesignSessionImpl.openDesign(DesignSessionImpl.java:218)
    	at org.eclipse.birt.report.model.api.SessionHandleImpl.openDesign(SessionHandleImpl.java:224)
    	at test.Initialize(test.java:63)
    	at main.main(main.java:13)
    Exception in thread "main" java.lang.NullPointerException
    	at test.Initialize(test.java:69)
    	at main.main(main.java:13)
    I am sure the location of file is exact... I am acessing it through a desktop app without any server or engine (Tomcat etc...)

  7. #7
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    It Solved.... Thanx Petr for your vvvvvvvvvvvvvvvv kind suggestion....I dont know how to repay u..... Thanx again , this forum and u are the best.

  8. #8
    Join Date
    Jul 2011
    Posts
    8
    Rep Power
    0

    Default

    I have connected it succesffuly , can u give me a small program to create a pdf from report?

Similar Threads

  1. Call jasper Reports from java
    By suresh_m5a5@yahoo.co.in in forum New To Java
    Replies: 1
    Last Post: 06-18-2012, 09:54 AM
  2. Replies: 0
    Last Post: 06-24-2011, 09:24 AM
  3. Replies: 0
    Last Post: 05-13-2011, 04:17 AM
  4. Replies: 9
    Last Post: 12-21-2010, 03:37 PM
  5. What to use for Pdf reports?
    By hari.kr in forum Advanced Java
    Replies: 2
    Last Post: 04-29-2010, 12:15 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
  •