|
Hello, I need change the Database dynamic of a Report, i use replaceConnection but not change the Database of rows in Report. (My report show a field (row) with information about table "Usuario" ). I need change database "DB1" (original) to "DB2" . (To show data of database "DB2" and not "DB1" ).
Connection work fine, but show data of DB1. (I need of DB2).
Code: <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%>
<%//Crystal Reports for Eclipse Version 2 imports.%> <%@ page import="com.crystaldecisions.sdk.occa.report.application.*"%> <%@ page import="com.crystaldecisions.sdk.occa.report.data.*"%> <%@ page import="com.crystaldecisions.sdk.occa.report.document.*"%> <%@ page import="com.crystaldecisions.sdk.occa.report.definition.*"%> <%@ page import="com.crystaldecisions.sdk.occa.report.lib.*" %>
<% //Report can be opened from the relative location specified in the CRConfig.xml, or the report location //tag can be removed to open the reports as Java resources or using an absolute path (absolute path not recommended //for Web applications). final String REPORT_NAME = "Report.rpt"; final String DBUSERNAME = "USER1"; final String DBPASSWORD = "PASS1";
final String CONNECTION_STRING = "jdbc:jtds:sqlserver://10.0.0.1:1433;DatabaseName=BD2;User=USER1;Password=PASS1"; final String TRUSTEDCON = "false"; final String PREQESERVERNAME = "jdbc:jtds:sqlserver://10.0.0.1:1433"; final String SERVERTYPE = "JDBC (JNDI)"; final String DATABASE_DLL = "crdb_jdbc.dll"; final String DATABASE = "BD2"; final String DBCLASSNAME = "net.sourceforge.jtds.jdbc.Driver"; final String USEJDBC = "true"; final String DATABASE_NAME = "BD2"; final String SERVERNAME = "jdbc:jtds:sqlserver://10.0.0.1:1433"; final String CONNECTIONURL = "jdbc:jtds:sqlserver://10.0.0.1:1433"; final String SERVER = "10.0.0.1"; %>
<%
try { //Open report. ReportClientDocument boReportClientDocument = new ReportClientDocument(); boReportClientDocument.open(REPORT_NAME, 0);
// Set DB Username and Password boReportClientDocument.getDatabaseController().logon(DBUSERNAME, DBPASSWORD); // Create the two connectioninfo objects to use IConnectionInfo oldConnectionInfo = new ConnectionInfo(); IConnectionInfo newConnectionInfo = new ConnectionInfo(); // Assign the old Connection info to the reports current info DatabaseController dbController = boReportClientDocument.getDatabaseController(); oldConnectionInfo = dbController.getConnectionInfos(null).getConnectionInfo(0);
// If this connection needed parameters, we would use this field. Fields pFields = null; // Create a new propertybag for the new location PropertyBag boPropertyBag1 = new PropertyBag(); // Set new table logon properties boPropertyBag1.put("JDBC Connection String", CONNECTION_STRING); boPropertyBag1.put("Trusted_Connection", TRUSTEDCON); boPropertyBag1.put("PreQEServerName", PREQESERVERNAME); boPropertyBag1.put("Server Type", SERVERTYPE); boPropertyBag1.put("Database DLL", DATABASE_DLL); boPropertyBag1.put("Database", DATABASE); boPropertyBag1.put("Database Class Name", DBCLASSNAME); boPropertyBag1.put("Use JDBC", USEJDBC); boPropertyBag1.put("Database Name", DATABASE_NAME); boPropertyBag1.put("Server Name", SERVERNAME); boPropertyBag1.put("Connection URL", CONNECTIONURL); boPropertyBag1.put("Server", SERVER);
// Assign the properties to the connection info newConnectionInfo.setAttributes(boPropertyBag1); // Set the DB Username and Pwd newConnectionInfo.setUserName(DBUSERNAME); newConnectionInfo.setPassword(DBPASSWORD); // The Kind of connectionInfos is SQL newConnectionInfo.setKind(ConnectionInfoKind.SQL);
// set the parameters to replace. // The 4 options are: // _doNotVerifyDB // _ignoreCurrentTableQualifiers // _mapFieldByRowsetPosition // _useDefault int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;
// Now replace the connections dbController.replaceConnection(oldConnectionInfo, newConnectionInfo, pFields, replaceParams); //Store the report source in session, will be used by the CrystalReportViewer. session.setAttribute("reportSource", boReportClientDocument.getReportSource()); //Launch CrystalReportViewer page that contains the report viewer. response.sendRedirect("CrystalReportViewer.jsp"); } catch(ReportSDKException ex) { out.println(ex); } catch(Exception ex) { out.println(ex); } %>
Sorry about my bad English....
Thanks.
|