Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8524

Re: How to switch database connection at runtime in crystal reports using java swing

$
0
0

Hi Expert,

 

I am trying to  change crystal report connection by using java code but I am not able to locate the jar files for below package.

 

import com.crystaldecisions.sdk.occa.managedreports.reportAppFactory;

import com.crystaldecisions.sdk.occa.report.application.databaseController;

import com.crystaldecisions.sdk.occa.report.lib.propertyBag;

 

Can you please let me know in which jar file above package would be there.

 

Sample Code:-

 

import com.businessobjects.rebean.wi.DocumentInstance;

import com.crystaldecisions.sdk.exception.SDKException;

import com.crystaldecisions.sdk.framework.CrystalEnterprise;

import com.crystaldecisions.sdk.framework.IEnterpriseSession;

import com.crystaldecisions.sdk.framework.ISessionMgr;

import com.crystaldecisions.sdk.occa.infostore.IInfoObject;

import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;

import com.crystaldecisions.sdk.occa.infostore.IInfoStore;

import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;

import com.crystaldecisions.sdk.occa.managedreports.reportAppFactory;

import com.crystaldecisions.sdk.occa.report.application.databaseController;

import com.crystaldecisions.sdk.occa.report.data.IConnectionInfo;

import com.crystaldecisions.sdk.occa.report.document.*;

import com.crystaldecisions.sdk.occa.report.definition.*;

import com.crystaldecisions.sdk.occa.report.lib.propertyBag;

 

 

 

 

 

 

class ChangeDataSource {

 

  void cmsconnect(String cmstext,String usetext,String passtext, String auttext)

  {

       String cms = cmstext;

       String username = usetext;

       String password = passtext;

       String auth = auttext;

            

       IEnterpriseSession enterpriseSession = null;

       ISessionMgr sessionMgr = null;//CrystalEnterprise.getSessionMgr();  

       Exception failure = null;

       boolean loggedIn = true;

 

 

       ReportClientDocument clientDoc = null;

 

 

       if (enterpriseSession == null)

       {

      try

      {

          sessionMgr = CrystalEnterprise.getSessionMgr();

 

 

          enterpriseSession = sessionMgr.logon(username, password, cms, auth);

          System.out.println("\nLOGIN SUCCESSFUL\n");

        

      }

      catch (Exception error)

      {

          loggedIn = false;

          failure = error;

      }

 

 

      if (!loggedIn)

      {

     

         System.out.println("\nLOGIN FAILED\n");

      }

   //Step 1..............................................................................................................................

      else

      {

          // Query for the sample report from the Enterprise CMS.

          try {

            IInfoStore iStore = (IInfoStore) enterpriseSession.getService("InfoStore");

            IInfoObjects infoObjects = iStore.query("Select SI_ID From CI_INFOOBJECTS Where SI_Type='CrystalReport'");

           

            System.out.println("\ninfoObjects size = "+infoObjects.getResultSize());

            IReportAppFactory reportAppFactory = (IReportAppFactory)enterpriseSession.getService("RASReportFactory");

 

  System.out.println(infoObjects.get(0));

           

            IInfoObject infoObject = (IInfoObject)infoObjects.get(0);

 

 

/* if (infoObjects != null) {

  Iterator lReportListIterator = lReportList.iterator();

  while (lReportListIterator.hasNext()) {

  IInfoObject infoObject = (IInfoObject) lReportListIterator.next();*/

           

            clientDoc = new ReportClientDocument();

            clientDoc = reportAppFactory.openDocument(infoObject,0, java.util.Locale.US);

            System.out.println("Report "+ infoObject.getTitle() +" Opened");  

           //Step2.......................................................................................................................................

           

  //switch_connection(clientDoc.getDatabaseController(),infoObject );

           

  }catch(ReportSDKException re){           

            re.printStackTrace();

         }catch(SDKException re){

            re.printStackTrace();

         }

      }

       }

   }

 

 

   private static void switch_connection(DatabaseController databaseController, IInfoObject REPORT_NAME) throws ReportSDKException {

 

 

     //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 = "change_db_location/simplereport.rpt";

final String DBUSERNAME = "vantech";

final String DBPASSWORD = "vantech";

 

 

final String CONNECTION_STRING = "!com.microsoft.jdbc.sqlserver.SQLServerDriver!jdbc:microsoft:sqlserver://10.50.212.103:1433;DatabaseName={database};user={userid};password={password}";

final String TRUSTEDCON = "false";

final String PREQESERVERNAME = "jdbc:microsoft:sqlserver://10.50.212.103:1433";

final String SERVERTYPE = "JDBC (JNDI)";

final String DATABASE_DLL = "crdb_jdbc.dll";

final String DATABASE = "Xtreme";

final String DBCLASSNAME = "com.microsoft.jdbc.sqlserver.SQLServerDriver";

final String USEJDBC = "true";

final String DATABASE_NAME = "Xtreme";

final String SERVERNAME = "jdbc:microsoft:sqlserver://10.50.212.103:1433";

final String CONNECTIONURL = "jdbc:microsoft:sqlserver://10.50.212.103:1433";

final String SERVER = "10.50.212.103";

           

  //Open report.

  ReportClientDocument boReportClientDocument = new ReportClientDocument();

  boReportClientDocument = reportAppFactory.openDocument(infoObject,0, java.util.Locale.US);

  //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();

 

       //System.out.println(oldConnectionInfo);

   //System.out.println(ToStringBuilder.reflectionToString(oldConnectionInfo));

 

// 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");

 

   }

 

I have added the most of the jar files but still not able to resolve the problem.

 

 

Thanks,

Sachin


Viewing all articles
Browse latest Browse all 8524

Trending Articles