Connecting to Java-based Data Sources

The COM Data Source driver is targeted at Visual Basic and Visual C++ developers. Because Crystal Reports 10 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
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 10";
        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_MACHINESoftwareCrystal DecisionsCrystal Reports 10DatabaseOptions
JavaUserClassPath

During the process of creating a report, Crystal Reports searches through all classes contained in the folder(s) specified in the Registry key discussed previously. It then provides a list of methods with return types of 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.55.18