Example 3: Developing reports from Java object data source UDS

The JReport Designer UDS can use any Java object as a data source for you to create reports. To implement this function, JReport Designer provides a class UDSForJavaBean, in which the getResultSet() method creates instances for the interface JavaBeanDataProvider, and then uses the method init() to initialize the data of the created instances.

Below is the Java code for class definition:

public class UDSForJavaBean implements JRUserDataSource 
{
	// Define data.
	public ResultSet getResultSet(String param)
			throws JRUserDataSourceException 
	{
		// Method body.
   }

	/**
	 * Free the resources such as : Connection, Statement, ResultSet.
	 */
	public void releaseResultSet() throws JRUserDataSourceException
   {
		// Method body.
	}
}

The interface JavaBeanDataProvider is defined as follows:

public interface JavaBeanDataProvider
{
    public void init(String dataID, Properties initprops)
		  throws JavaBeanDataProviderException;
	 public Class getMetadataJavaBean()
		  throws ClassNotFoundException;
	 public Object next() throws JavaBeanDataProviderException;
	 public boolean requireDetails(String collectionPropName);
	 public int getMaxShareTimes(String collectionPropName);
	 public int getTimeoutForSubCollection(String collectionPropName);
	 public void exit()throws JavaBeanDataProviderException;
}

For examples of how to create reports using the Java object data interface, JReport provides you with two demos which are available in <install_root>\help\samples\APIUDS\javaUDS.