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 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.