cancel
Showing results for 
Search instead for 
Did you mean: 

can't get JRCChangeDatabaseConnection.java to work with runtime_12.2.211

Former Member
0 Kudos

The sample program JRCChangeDatabaseConnection.java throws an exception when run with crjava-runtime_12.2.211.zip <br/>

when it gets to the line that does a setTableLocation.<br/>

<br/>

The exception is java.lang.UnsupportedOperationException.<br/>

<br/>

<br/>

My question is:<br/>

how do I get a Java program to run a Crystal Report from version 2008,<br/>

specifically, how to set the database connection information?<br/>

<br/>

notes:<br/>

The original report was created with Crystal Reports 2008.<br/>

It was created using ODBC to connect to the database.<br/>

It is a very simple report for testing, no sub reports, one table.<br/>

The JRCChangeDatabaseConnection.java program required changes before I could get it to compile.<br/>

Most of the changes are to use a diferent database/user/password/jdbc driver.<br/>

I'm trying to run a report directly from Java, not servlet/jsp/web server involved.<br/>

<br/>

Details:<br/>

<br/>

First I altered the JRCChangeDatabaseConnection.java so that it would compile an run.<br/>

It did run using the jar files from crystalreports-javasdk-11.8.8.zip.<br/>

Except it got this message:<br/>

Register for FREE at www.businessobjects.com/eclipse to remove this message<br/>

by searching around I relalized that I was not using the most recent .jar files.<br/>

This is what the program output when it ran:<br/>

Crystal Report Viewer 11.8.8.1541<br/>

java.vendor = Sun Microsystems Inc.<br/>

java.version = 1.6.0_22<br/>

os.name = Windows 7<br/>

os.version = 6.1<br/>

os.arch = x86<br/>

<br/>

so I moved to a new set of jar files from crjava-runtime_12.2.211.zip.<br/>

This gave me this output:<br/>

0 [AWT-EventQueue-0] FATAL com.businessobjects.reports.sdk.JRCCommunicationAdapter - Request failed and JRC Command failed to be undone<br/>

2 [AWT-EventQueue-0] ERROR com.businessobjects.reports.sdk.JRCCommunicationAdapter - detected an exception: java.lang.UnsupportedOperationException<br/>

<br/>

com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: java.lang.UnsupportedOperationException---- Error code:-2147467259 Error code name:failed<br/>

<br/>

at statement:<br/>

databaseController.setTableLocation(table, tables.getTable(i));<br/>

<br/>

as well as a full stack trace (included below).<br/>

the program would output this if I commented out the offending line:<br/>

Crystal Reports Viewer 12.0.0.0<br/>

java.vendor = Sun Microsystems Inc.<br/>

java.version = 1.6.0_22<br/>

os.name = Windows 7<br/>

os.version = 6.1<br/>

os.arch = x86<br/>

but ofcourse the program would not connect to the database with that line commented out.<br/>

<br/>

here is the stack trace (trimmed because I exceeded the character limit):<br/>

<br/>

$ javac JRCChangeDatabaseConnection.java<br/>

$ java JRCChangeDatabaseConnection<br/>

0 [AWT-EventQueue-0] FATAL com.businessobjects.reports.sdk.JRCCommunicationAdapter - Request failed and JRC Command fai

led to be undone

2 [AWT-EventQueue-0] ERROR com.businessobjects.reports.sdk.JRCCommunicationAdapter - detected an exception: java.lang.

UnsupportedOperationException

at sun.jdbc.odbc.JdbcOdbcDatabaseMetaData.getUDTs(Unknown Source)

at com.crystaldecisions.reports.queryengine.driverImpl.jdbc.JDBCConnection.GetTables(Unknown Source)

at com.crystaldecisions.reports.queryengine.JDBConnectionWrapper.GetTables(SourceFile:112)

at com.crystaldecisions.reports.queryengine.Connection.be(SourceFile:1048)

at com.crystaldecisions.reports.queryengine.Table.bv(SourceFile:2296)

at com.crystaldecisions.reports.queryengine.Table.a(SourceFile:581)

at com.crystaldecisions.reports.queryengine.Table.u7(SourceFile:2405)

at com.crystaldecisions.reports.dataengine.datafoundation.AddDatabaseTableCommand.new(SourceFile:529)

at com.crystaldecisions.reports.common.CommandManager.a(SourceFile:71)

at com.crystaldecisions.reports.common.Document.a(SourceFile:203)

at com.businessobjects.reports.sdk.requesthandler.f.a(SourceFile:175)

at com.businessobjects.reports.sdk.requesthandler.DatabaseRequestHandler.byte(SourceFile:1079)

at com.businessobjects.reports.sdk.JRCCommunicationAdapter.do(SourceFile:1167)

at com.businessobjects.reports.sdk.JRCCommunicationAdapter.if(SourceFile:661)

at com.businessobjects.reports.sdk.JRCCommunicationAdapter.a(SourceFile:167)

at com.businessobjects.reports.sdk.JRCCommunicationAdapter$2.a(SourceFile:529)

at com.businessobjects.reports.sdk.JRCCommunicationAdapter$2.call(SourceFile:527)

at com.crystaldecisions.reports.common.ThreadGuard.syncExecute(SourceFile:102)

at com.businessobjects.reports.sdk.JRCCommunicationAdapter.for(SourceFile:525)

at com.businessobjects.reports.sdk.JRCCommunicationAdapter.int(SourceFile:424)

at com.businessobjects.reports.sdk.JRCCommunicationAdapter.request(SourceFile:352)

at com.businessobjects.sdk.erom.jrc.a.a(SourceFile:54)

at com.businessobjects.sdk.erom.jrc.a.execute(SourceFile:67)

at com.crystaldecisions.proxy.remoteagent.RemoteAgent$a.execute(SourceFile:716)

at com.crystaldecisions.proxy.remoteagent.CommunicationChannel.a(SourceFile:125)

at com.crystaldecisions.proxy.remoteagent.RemoteAgent.a(SourceFile:537)

at com.crystaldecisions.sdk.occa.report.application.ds.a(SourceFile:186)

at com.crystaldecisions.sdk.occa.report.application.an.a(SourceFile:108)

at com.crystaldecisions.sdk.occa.report.application.b0.if(SourceFile:148)

at com.crystaldecisions.sdk.occa.report.application.b0.b(SourceFile:95)

at com.crystaldecisions.sdk.occa.report.application.bb.int(SourceFile:96)

at com.crystaldecisions.proxy.remoteagent.UndoUnitBase.performDo(SourceFile:151)

at com.crystaldecisions.proxy.remoteagent.UndoUnitBase.a(SourceFile:106)

at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(SourceFile:2159)

at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(SourceFile:543)

at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(SourceFile:3898)

at com.crystaldecisions.sdk.occa.report.application.DatabaseController.setTableLocation(SourceFile:2906)

at com.crystaldecisions.reports.sdk.DatabaseController.setTableLocation(SourceFile:51)

at JRCChangeDatabaseConnection.switch_tables(JRCChangeDatabaseConnection.java:151)

at JRCChangeDatabaseConnection.launchApplication(JRCChangeDatabaseConnection.java:46)

at JRCChangeDatabaseConnection$1.run(JRCChangeDatabaseConnection.java:168)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

$<br/>

<br/>

here is the full program:<br/>


//Crystal Java Reporting Component (JRC) imports.
import com.crystaldecisions.ReportViewer.ReportViewerBean;
import com.crystaldecisions.reports.sdk.*;
import com.crystaldecisions.sdk.occa.report.lib.*;
import com.crystaldecisions.sdk.occa.report.data.*;

//Java Imports.
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Insets;

import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;

public class JRCChangeDatabaseConnection extends JFrame {

	private static final String REPORT_NAME = "room_test_nw_src.rpt";
		
	public static void launchApplication() {
		
		try {
										
			//Open report.
			ReportClientDocument reportClientDoc = new ReportClientDocument();
			reportClientDoc.open(REPORT_NAME, 0);
				
			//The DatabaseController will be used to modify the connection properties of the database before 
			//viewing the report.  This method iterates through each table in the report and changes the 
			//connection info properties.  
			
			//Switch all tables on the main report.  See utility method below.
			switch_tables(reportClientDoc.getDatabaseController());
			
			//Perform the same operation against all tables in the subreport as well.
			IStrings subreportNames = reportClientDoc.getSubreportController().getSubreportNames();
			
			//Set the datasource for all the subreports.
			for (int i = 0; i < subreportNames.size(); i++ ) {
				ISubreportClientDocument subreportClientDoc = reportClientDoc.getSubreportController().getSubreport(subreportNames.getString(i));
				
				//Switch tables for each subreport in the report using the same connection information.  See utility
				//method below.
				switch_tables(subreportClientDoc.getDatabaseController());
								
			}	
			
			//Launch JFrame that contains the report viewer.
			//new ReportViewerFrame(reportClientDoc);		
			//
		    ReportViewerBean reportViewerBean = new ReportViewerBean();
		    reportViewerBean.init();
		    reportViewerBean.setReportSource(reportClientDoc.getReportSource());
	    
		    JRCChangeDatabaseConnection frame = new JRCChangeDatabaseConnection();
		    frame.getContentPane().add(reportViewerBean, BorderLayout.CENTER);
		    Insets insets = frame.getInsets();
		    frame.setSize(insets.left + 700 + insets.right, insets.top + 500 + insets.bottom);
		    frame.setLocationByPlatform(true);
		    frame.setVisible(true);
	
		    reportViewerBean.start();
		}
		catch(ReportSDKException ex) {	
			ex.printStackTrace();
		}
		catch(Exception ex) {
			ex.printStackTrace();
		}
		
	}
	
	/**
	 * Sample utility method for switching the database connection properties of all tables accessible from a databaseController 
	 * (i.e., could be a main report database controller, or a subreport's database controller) from one database to another. 
	 */ 
	private static void switch_tables(DatabaseController databaseController) throws ReportSDKException {

		//Declare the new connection properties that report's datasource will be switched to.
		//NOTE: These are specific to using JDBC against a particular MS SQL Server database.  Be sure to use the 
		//DisplayConnectionInfo sample to determine what your own connection properties need to be set to.
		final String TABLE_NAME_QUALIFIER = "nw_src.dbo.";
		final String DBUSERNAME = "sa";
		final String DBPASSWORD = "password";
		final String SERVERNAME = "192.168.1.113"; 
		final String CONNECTION_STRING = "Use JDBC=b(true);Connection URL=s(jdbc:microsoft:sqlserver://vancsdb02.crystald.net:1433);" + 
										 "Database Class Name=s(com.microsoft.jdbc.sqlserver.SQLServerDriver);Server=s(vancsdb02.crystald.net);" + 
										 "User ID=s(vantech);Password=;Database=s(Xtreme1);Trusted_Connection=b(false);" + 
										 "JDBC Connection String=s(!com.microsoft.jdbc.sqlserver.SQLServerDriver!jdbc:microsoft:sqlserver://vancsdb02.crystald.net:1433;" + 
										 "DatabaseName={database};user={userid};password={password}!)";
		final String DATABASE_NAME = "nw_src";
		final String URI = "!sun.jdbc.odbc.JdbcOdbcDriver!jdbc:odbc:nw_src!";
		final String DATABASE_DLL = "crdb_jdbc.dll";
		
		//Obtain collection of tables from this database controller.
		Tables tables = databaseController.getDatabase().getTables();

		//Set the datasource for all main report tables.
		for (int i = 0; i < tables.size(); i++) {

			ITable table = tables.getTable(i);

			//Keep existing name and alias.
			table.setName(table.getName());
			table.setAlias(table.getAlias());
							
			//Change properties that are different from the original datasource.
			table.setQualifiedName(TABLE_NAME_QUALIFIER + table.getName());
			
			//Change connection information properties.
			IConnectionInfo connectionInfo = table.getConnectionInfo();
							
			//Set new table connection property attributes.
			PropertyBag propertyBag = new PropertyBag();
			
			//Overwrite any existing properties with updated values.
			propertyBag.put("Trusted_Connection", "false");
			propertyBag.put("Server Name", SERVERNAME); //Optional property.
			propertyBag.put("Connection String", CONNECTION_STRING);
			propertyBag.put("Database Name", DATABASE_NAME);
			propertyBag.put("Server Type", "JDBC (JNDI)");
			propertyBag.put("URI", URI);
			propertyBag.put("Use JDBC", "true");
			propertyBag.put("Database DLL", DATABASE_DLL);
					
			connectionInfo.setAttributes(propertyBag);
			
			//Set database username and password.
			//NOTE: Even if these the username and password properties don't change when switching databases, the 
			//database password is *not* saved in the report and must be set at runtime if the database is secured.  
			connectionInfo.setUserName(DBUSERNAME);
			connectionInfo.setPassword(DBPASSWORD);
			connectionInfo.setKind(ConnectionInfoKind.SQL);
							
			table.setConnectionInfo(connectionInfo);
			
			//Update old table in the report with the new table.
			databaseController.setTableLocation(table, tables.getTable(i));
			
		}
				
	}
	
	public static void main(String [] args) {
		
		BasicConfigurator.configure();

		//Event-dispatching thread to run Swing GUI.  This is good practice for Swing applications
		//to help ensure that events are dispatched in a predicatable order. 
		//For more information on using this method, refer to the SUN site below for more details:
		//http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
		SwingUtilities.invokeLater(new Runnable() { 
			public void run() {
				//Hand-off to worker function to start application.
				launchApplication();				
			}
		});
					
	}
	
}

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Rob,

I am getting the same error while running my report created using ODBC in Crystal Report viewer. I am using the latest CR JAVA runtime as well as JDK 1.7. Can you please suggest how to fix it? Appreciate your quick response.

Regards,

Murtaza Ghodawala

murtaza_ghoda82@hotmail.com

+965 97180549