×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

BO SDK Crystal Report

BO SDK Crystal Report

BO SDK Crystal Report

(OP)
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[i] = new Object();
paramObj1[i] = paramValue1[i];
}
// 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[i] = new Object();
paramObj2[i] = paramValue2[i];
}
// 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.

RE: BO SDK Crystal Report

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
www.decisionfirst.com

RE: BO SDK Crystal Report

(OP)
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.

RE: BO SDK Crystal Report

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
www.decisionfirst.com

RE: BO SDK Crystal Report

(OP)
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

RE: BO SDK Crystal Report

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
www.decisionfirst.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close