The COM Data Source driver is targeted at Visual Basic and Visual C++, and ADO.NET is targeted at .NET developers. Because Crystal Reports XI has a full Java SDK, an equivalent Java Data Source driver provides equivalent functionality of the COM driver for developers using the Java platform. The process of creating a Java Data Source driver is conceptually similar to that of creating a COM Data Source driver. A Java class needs to be created that has a public function with a return type of ResultSet or CachedRowSet. A ResultSet is the standard object returned from a JDBC-based query, whereas the CachedRowSet is a disconnected recordset useful for parsing out things like XML. Listing 15.2 shows a simple Java Data Provider that returns a ResultSet. Listing 15.2. A Java Data Provider That Returns Data from the Sample Database
To identify a Java class, simply compile the code into the .class file and place that compiled .class file into the JavaBeans classpath. To define the classpath, edit the following properties in the CRconfig.xml file in the default folder: C:\Program Files\Common Files\Business Objects\3.0\java\. JavaDirThis property must refer to a valid Java Runtime Environment (JRE) or J2SE Development Kit (JDK). If a JRE or JDK was detected during install, this property will already be set. If not, install JDK 1.4 and set the property manually. A valid setting is the complete path to the JDK: <JavaDir>c:\Program Files\Java\JRE\bin</JavaDir> JavaBeansClassPathIf the JavaBeans are unjarred, simply refer to the .class file's path: <JavaBeans> <CacheRowSetSize>100</CacheRowSetSize> <JavaBeansClassPath>c:\myjavabean</JavaBeansClassPath> </JavaBeans> and if the JavaBean class files are jarred, refer to the same location with the .jar extension: <JavaBeans> <CacheRowSetSize>100</CacheRowSetSize> <JavaBeansClassPath>c:\myjavabean.jar</JavaBeansClassPath> </JavaBeans> During the process of creating a report, Crystal Reports searches through all classes contained in the classpath. It then provides a list of methods with return types of java.sql.ResultSet. The same rules about function arguments apply. Any arguments to the Java method are mapped to report parameter fields. Using Java code, you can control exactly what data comes back. |