on 03-01-2015 12:17 AM
Dear all,
Is there any simple sample to show how to display rpt via dynamic XML datasource during runtime.
This is the current environment: jdk 1.6, crystal report xi, tomcat 5.5. Now I could new crystal report using XML datasouce when development. what I what is to modify the path of xml file in the JSP page.
I did a lot of search but with no luck. Result shows a lot of examples for database connection modification in runtime.
Best Regards
Rodney Huang
HI Rodney
I don't deal with Java at all, but maybe these sample apps will help:
Java JRC Set Resultset Datasource | SCN
CRJava Result Set Data Source | SCN
If not, I'll see about chasing someone down that will be able to help.
- Ludek
Senior Support Engineer AGS Product Support, Global Support Center Canada
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Ludek,
Many thanks for your helpful reply and it makes my mind much more clear. Now my problem goes clear as "How to change XML connection property in runtime".
Just found one similar question as this at below address:
http://scn.sap.com/thread/1247885
In above topic, Ted used to said below:
"You can switch XML datasource by changing the connection info properties before running the document. So if the report remains unchanged but you just want a different datasource for the report, it'll be just doing replaceConnection as you would with any other data source type".
May I know where to find the JSP sample to show the code snippet about "switch XML datasource"?
Best Regards,
Rodney
Dear Lude,
Finally I make it happen with below code:
* The basic idea is to updatethe conneciton information in runtime.
<%@ page import="com.crystaldecisions.report.web.viewer.CrystalReportViewer,
java.io.ByteArrayInputStream,
java.sql.Connection,
java.sql.DriverManager,
java.sql.ResultSet,
java.sql.Statement,
com.crystaldecisions.sdk.occa.report.data.*,
com.crystaldecisions.sdk.occa.report.application.DatabaseController,
com.crystaldecisions.sdk.occa.report.application.DBOptions,
com.crystaldecisions.sdk.occa.report.application.OpenReportOptions,
com.crystaldecisions.sdk.occa.report.application.ReportClientDocument,
com.crystaldecisions.sdk.occa.report.lib.*,
com.crystaldecisions.sdk.occa.report.exportoptions.*;
"
%><%
String reportPath;
ReportClientDocument reportClientDocument;
Connection connection;
Statement statement;
ResultSet resultSet;
ByteArrayInputStream byteArrayInputStream;
byte[] byteArray;
int bytesRead;
reportPath = "TEST/po.rpt";
final String LOCAL_SCHEMA_FILE = "D:\\po.xsd";
final String SERVER_TYPE = "XML";
final String PREQESERVERNAME = "D:\\po.xml D:\\po.xsd";
final String DATABASE_DLL = "crdb_xml.dll";
final String PREQESERVERTYPE = "XML";
final String SERVER_NAME = "D:\\po.xml D:\\po.xsd";
final String LOCAL_XML_FILE = "D:\\po.xml";
reportClientDocument = new ReportClientDocument();
reportClientDocument.open(reportPath, 0);
IConnectionInfo oldConnectionInfo = new ConnectionInfo();
IConnectionInfo newConnectionInfo = new ConnectionInfo();
DatabaseController dbController = reportClientDocument.getDatabaseController();
oldConnectionInfo = dbController.getConnectionInfos(null).getConnectionInfo(0);
PropertyBag boPropertyBag1 = new PropertyBag();
boPropertyBag1.put("Database DLL", DATABASE_DLL);
boPropertyBag1.put("PreQEServerName", PREQESERVERNAME);
boPropertyBag1.put("PreQEServerType", PREQESERVERTYPE);
boPropertyBag1.put("Server Type", SERVER_TYPE);
boPropertyBag1.put("Server Name", SERVER_NAME);
boPropertyBag1.put("Local XML File", LOCAL_XML_FILE);
boPropertyBag1.put("Local Schema File", LOCAL_SCHEMA_FILE);
newConnectionInfo.setAttributes(boPropertyBag1);
int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;
dbController.replaceConnection(oldConnectionInfo, newConnectionInfo, null, replaceParams);
session.setAttribute("reportSource", reportClientDocument.getReportSource());
byteArrayInputStream = (ByteArrayInputStream) reportClientDocument
.getPrintOutputController().export(ReportExportFormat.PDF);
response.reset();
response.setHeader("Content-disposition", "inline;filename=crreport.pdf");
response.setContentType("application/pdf");
byteArray = new byte[1024];
while((bytesRead = byteArrayInputStream.read(byteArray)) != -1) {
response.getOutputStream().write(byteArray, 0, bytesRead);
}
response.getOutputStream().flush();
response.getOutputStream().close();
reportClientDocument.close();
%>
Dear Ludek,
Just share one import note: in web project, we need to copy XMLConnector.jar into bin folder of TOMCAT. Otherwise we will meet exception about database connection loading which is another common question in the community.
* XMLConnector.jar is included in crystal report java runtime.
Have a nice day.
Best Regards,
- Rodney
Moved to Java SDK forum...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.