Java-based Data Sources

The COM Data Source Driver is targeted at Visual Basic and Visual C++ developers. Because Crystal Reports 9 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 java.sql.ResultSet. Listing 21.2 shows a simple Java Data Provider.

Listing 21.2 A Java Data Provider that Parses Data from a CSV File
 import java.lang.*; import java.sql.*; public class XtremeDataProvider {     public ResultSet Employee()     {     // connect to the database     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");         String url = "jdbc:odbc:Xtreme Sample Database 9";         Connection con = DriverManager.getConnection(url, "", "");     // run a SQL query         Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);                          String query = "SELECT * FROM Employee";     ResultSet rs = stmt.executeQuery(query);     // return the results of the query         return rs;     } } 

To identify a Java class, instead of typing in its name, place the .class file into a given directory, and add that directory's name to the following registry key of your Windows operating system:

 HKEY_LOCAL_MACHINE\Software\Crystal Decisions\Crystal Reports  9\DatabaseOptions\JavaUserClassPath 

During the process of creating a report, Crystal Reports will search through all classes contained in the folder(s) specified in the registry key discussed previously. It will then provide a list of methods with return types of ResultSet. The same rules about function arguments apply. Any arguments to the Java method will be mapped to report parameter fields. Using Java code, you can control exactly what data comes back.



Sams Teach Yourself Crystal Reports 9 in 24 Hours
Sams Teach Yourself Crystal Reports 9 in 24 Hours
ISBN: B003D7JUVW
EAN: N/A
Year: 2005
Pages: 230

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net