techie logo

The Ultimate Business Objects Resource Portal from Techieindex

Sitemap  |  Feedback  |  Contact Us

About Business Objects 
Products 
FAQ 
Consulting Centers  
Training Center 
News 
Events 
Articles 
Technology Tracks 
White Papers
Interviews
ROI 
Success Stories 
Guides 



 

 

 

 

 

 

How to create a simple Java Bean and a report using it
12-03-2006

Article refers to:
Crystal Reports XI



Symptom



Creating a Java Bean class and
report using it




Cause



Usage of Java Bean functionality.



Resolution



In order to use a simple Java
Bean in a report you can to follow the steps below.


Create a java class containg an
empty contructor and at least a method returning resultset.


In a command line go to the
directory containing the class. Compile the class using the java command: javac
*.java


Open the CRConfig.xml file of
your crystal report application (C:Program FilesBusiness
Objectscommon3.5java) or your java web application. Update the value of the
JavaBeansClassPath using the complete path to the class file you just created.


Start your Crystal Report
application and choose as a data source theJavaBean.


Java Bean Sample provided by :
CRSampleDataSourceBean.java


//package
com.romofabrics.reporting;


import
java.io.FileNotFoundException;


import java.io.FileOutputStream;


import java.io.PrintWriter;


import java.sql.*;


/*


 *
<p>Title: Java Bean Data Source Sample</p>


 *
<p>Description: Sample to demonstrate how to create a Java


 *
Bean report data source with Crystal Reports XI</p>


 *
<p>Copyright: Copyright (c) 2005</p>


 *
<p>Company: Business Objects</p>


 *
For Crystal Reports XI Release 2


 */


/*


 *
For information on how to use JDBC and ResultSets see Sun's


 *
tutorials and guides at


 *
<http://java.sun.com/products/jdbc/learning.html>.


 */


public class
CRSampleDataSourceBean


           
private ResultSet resultSet = null;


 


           
private Connection connection = null;


 


           
private String connectionURL = "jdbc:odbc:Xtreme Sample Database
11.5";


 


           
private String databaseClass = "sun.jdbc.odbc.JdbcOdbcDriver";


 


           
private String query = "SELECT * FROM CUSTOMER";


 


           
public CRSampleDataSourceBean() {


                       
try {


                                   
// Ensure database class exists


                                   
Class.forName(databaseClass);


                                   
// Create a connection


                                   
connection = DriverManager.getConnection(connectionURL, "",
"");


                       
{} catch (ClassNotFoundException ex)


                                   
System.out.println("Ensure that database driver class is installed.");


                                   
ex.printStackTrace();


                       
{} catch (SQLException ex)


                                   
System.out.println("SQL Exception #" + ex.getErrorCode() + " :
"


                                                           
+ ex.getLocalizedMessage());


                                   
ex.printStackTrace();


               
{}


           
}


 


           
/*


           
 * Any function that returns a
java.sql.ResultSet within the Java class can


           
 * be used in Crystal Reports to
return report data. The function can also


           
 * be parameterized to 'feed' in
specific values to the function when


           
 * querying.


           
 */


           
public ResultSet getResultSet() throws SQLException


                       
// Create an SQL statement to execute


                       
Statement statement = connection.createStatement(


                                               
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);


                       


                       
// Execute the select statement to populate the ResultSet


                       
resultSet = statement.executeQuery(query);


                       
return resultSet;


           
{}


}



Additional information can be found at http://technicalsupport.businessobjects.com/KanisaSupportSite/dynamickc.do?externalId=5899241&sliceId=&command=show&forward=nonthreadedKC&kcId=5899241

Copyright 2007 Techieindex

 

-