Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BO SDK Crystal Report

Status
Not open for further replies.

litulima

Programmer
Sep 5, 2012
6
0
0
SG
Hello All,

I am new to this group . I am presently working on BO SDK which uses crystal report(*.rpt ).
The BO team here creates a report and give us the *.rpt file which we export to pdf or csv.The report fetches data from DB. The BO team is saying that the report connects to DB and execute query just we have to pass parameters.
I am setting parameters to my report but it is not working saying ReportSDKException
Error finding JNDI name (DNY08600)---- Error code:-2147467259 Error code name:failed
package poc.sdk;


//Crystal Java Reporting Component (JRC) imports.
//import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;
import com.crystaldecisions.reports.queryengine.Session;
import com.crystaldecisions.reports.sdk.*;
import com.crystaldecisions.sdk.occa.report.lib.*;
import com.crystaldecisions.sdk.occa.report.data.*;
import com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat;

//Java Imports.
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;

public class ReportParameterPassing {

private static final String REPORT_NAME = "C:\\rptfiles\\Test.rpt";
private static final String EXPORT_FILE = "myExportedReport.pdf";
private static final String EXPORT_LOC = "C:\\rptfiles\\pdf\\";

public static void launchApplication() {

try {

// Open report.
ReportClientDocument reportClientDoc = new ReportClientDocument();

reportClientDoc.open(REPORT_NAME, 0);

// We will be using the ParameterFieldController quite a bit
// through-out the rest of this function.
ParameterFieldController paramFieldController = reportClientDoc.getDataDefController().getParameterFieldController();

//reportClientDoc.getDatabaseController().

String[] paramValue1 = { "DSO" };
String paramName1 = "Party Name";

// Using Multiple Parameters
Object[] paramObj1 = new Object[paramValue1.length];

for (int i = 0; i < paramValue1.length; i++) {
paramObj1 = new Object();
paramObj1 = paramValue1;
}
// Limiting the Report with Parameters
paramFieldController.setCurrentValues("", paramName1, paramObj1);



String[] paramValue2 = { "BP Corp North America Inc" };
String paramName2 = "Party Legal Name";
// Using Multiple Parameters
Object[] paramObj2 = new Object[paramValue2.length];

for (int i = 0; i < paramValue2.length; i++) {
paramObj2 = new Object();
paramObj2 = paramValue2;
}
// Limiting the Report with Parameters
reportClientDoc.getDataDefController().getParameterFieldController().setCurrentValues("", paramName2, paramObj2);



System.out.println("*********************");

for (int i = 0 ; i < reportClientDoc.getDataDefController().getDataDefinition().getParameterFields().size();i++)
{
IField if1 = reportClientDoc.getDataDefController().getDataDefinition().getParameterFields().getField(i);
System.out.println("Creating A DataSource0..." + if1.getDescription());
System.out.println("Creating A DataSource0..." + if1.getType());
System.out.println("Creating A DataSource1..." + if1.getName());
System.out.println("Creating A DataSource2..." + if1.getHeadingText());
}

// Exporting the Report



System.out.println("Exporting the Report...");
ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) reportClientDoc
.getPrintOutputController().export(ReportExportFormat.PDF);

// Writing To Disk
System.out.println("Writing To Disk...");
String EXPORT_OUTPUT = EXPORT_LOC + EXPORT_FILE;

// Exported Report location
System.out.println("Exporting to " + EXPORT_OUTPUT);

// Write To File

writeToFileSystem(byteArrayInputStream, EXPORT_OUTPUT);

System.out.println("Writing to Disk Completed");

reportClientDoc.close();

} catch (ReportSDKException ex) {
System.out.println(ex);
} catch (Exception ex) {
System.out.println(ex);
}

}
private static void writeToFileSystem(
ByteArrayInputStream byteArrayInputStream, String eXPORT_OUTPUT) {
// Writing The File
System.out.println("Writing the File...");
try {
// Use the Java I/O libraries to write the exported content to the
// file system.
byte byteArray[] = new byte[byteArrayInputStream.available()];

// Create a new file that will contain the exported result.
File file = new File(eXPORT_OUTPUT);
FileOutputStream fileOutputStream = new FileOutputStream(file);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(
byteArrayInputStream.available());
int x = byteArrayInputStream.read(byteArray, 0,
byteArrayInputStream.available());
byteArrayOutputStream.write(byteArray, 0, x);
byteArrayOutputStream.writeTo(fileOutputStream);
// Close streams.
byteArrayInputStream.close();
byteArrayOutputStream.close();
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
launchApplication();
}
}



but when I am creating the connection and adding below lines before passing parameters it is working fine :

for (int i = 0; i < dbTables.size(); i++) {

String tableAlias = reportClientDoc.getDatabaseController()
.getDatabase().getTables().getTable(i).getAlias();

System.out.println("oldAlias 1111 >>>>>"
+ dbTables.getTable(i).getName());

//String qu1 = ""
String query = "select * from " + dbTables.getTable(i).getName();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

results.put(tableAlias, rs);
}

//

// Setting the DataSource in Report
final Enumeration<String> aliasEnumeration = Collections
.enumeration(results.keySet());
while (aliasEnumeration.hasMoreElements()) {
String oldAlias = aliasEnumeration.nextElement();
System.out.println("oldAlias >>>>>" + oldAlias);
ResultSet rs = results.get(oldAlias);
reportClientDoc.getDatabaseController().setDataSource(rs,oldAlias,oldAlias+"_rs");
}

I just need to Ask if BO people is creating connection and executing query why I have to set result set to report datasource.
 
I haven't worked in the Java SDK for this, but I have extensive experience in the .NET SDK which is similar. In your original code, I don't see that you set the database logon anywhere. That could be what's causing your problem. In a ReportDocument in .NET I have to go to each of the DataSourceConnections and call SetConnection to set the logon for the database.

-Dell

DecisionFirst Technologies - Six-time SAP BusinessObjects Solution Partner of the Year
 
Actually I have taken connection and my question is different . Suppose I have a query which pulls data from 5 tables then
I have to call reportClientDoc.getDatabaseController().setDataSource(rs,oldAlias,oldAlias+"_rs") five time with 5 hits to database which is not something good for performance.

I just need to know how are you writing code when you have to pull data from 5 different tables.
 
Usually when I'm using the Crystal SDK, I load the data into an in-memory dataset in my project and connect the report to that instead of to the database directly. That way I have more granular control over how the SQL runs. I'm not sure how to do that with Java, though.

Are you sure that each call to setDataSource is doing a separate log-in to the database? Based on how thinks work in the Crystal designer, I think it may connect with the first call and then for each successive call check to see whether that connection has already been made prior to trying to connect again.

-Dell

DecisionFirst Technologies - Six-time SAP BusinessObjects Solution Partner of the Year
 
You are right connection is done only once but the SQL Query is fired in loop based on the number of tables.
Are you keeping your report file locally or keeping it in the enterprise server
 
Ahh, I think I know what's going on - Turn off "Verify on First Refresh" for your report. It's on the File|Report Options menu. The 5 queries are the report verifying that all of the tables have the same data structure as when the report was created.

-Dell

DecisionFirst Technologies - Six-time SAP BusinessObjects Solution Partner of the Year
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top