如何在java swing应用程序中打开crystal report?
我有这个密码如何在java swing应用程序中打开crystal report?,java,swing,crystal-reports,crystal-reports-xi,Java,Swing,Crystal Reports,Crystal Reports Xi,我有这个密码 import com.crystaldecisions.reports.sdk.ReportClientDocument; ... ReportClientDocument rpt = new ReportClientDocument(); rpt.open(reportPath+fileName, 0); rpt.getDatabaseController().logon(DBConnect.getUsername(), DBConnect.getPasswo
import com.crystaldecisions.reports.sdk.ReportClientDocument;
...
ReportClientDocument rpt = new ReportClientDocument();
rpt.open(reportPath+fileName, 0);
rpt.getDatabaseController().logon(DBConnect.getUsername(), DBConnect.getPassword());
Tables tables = rpt.getDatabaseController().getDatabase().getTables();
for(int i=0; i< tables.size(); i++){
System.out.print(i);
ITable table = tables.getTable(i);
IConnectionInfo connInfo = table.getConnectionInfo();
PropertyBag innerProp = connInfo.getAttributes();
innerProp.clear();
PropertyBag propertyBag = new PropertyBag();
propertyBag.put("Server Type", "JDBC (JNDI)");
propertyBag.put("Database DLL", "crdb_jdbc.dll");
propertyBag.put("Connection String", DBConnect.getConnectionString());
propertyBag.put("Database Class Name", "com.mysql.jdbc.Driver");
propertyBag.put("Use JDBC", "true");
propertyBag.put("Server Name", DBConnect.getServer());
propertyBag.put("Generic JDBC Driver Behavior", "No");
propertyBag.put("URI", "!com.mysql.jdbc.Driver!jdbc:mysql://"+DBConnect.getServer()+":"+DBConnect.getPort()+"/"+DBConnect.getDatabase()+"!ServerType=29!QuoteChar=`");
connInfo.setAttributes(propertyBag);
connInfo.setKind(ConnectionInfoKind.SQL);
table.setConnectionInfo(connInfo);
rpt.getDatabaseController().setTableLocation(table, tables.getTable(i));
导入com.crystaldecisions.reports.sdk.ReportClientDocument;
...
ReportClientDocument rpt=新的ReportClientDocument();
打开(报告路径+文件名,0);
rpt.getDatabaseController().logon(DBConnect.getUsername(),DBConnect.getPassword());
Tables Tables=rpt.getDatabaseController().getDatabase().getTables();
对于(int i=0;i
我试图做的是打开一个报表,并将连接信息传递给该报表,这样我就可以动态更改报表的数据库,但由于某些原因,它不起作用,报表仍然从最初设置的数据库生成信息。有人能告诉我我做错了什么吗?这是一个swing应用程序我使用COM.StRealDigaRuns.RePvices。SDK.RePosiclitDebug代替COM.StRigalDealOn.SDK.OcCA.RePo.Aptual.RePosicli席文档,因为当我使用另一个时,我得到了一个找不到的服务器错误。请帮助。< /P> < P>在运行时切换连接,您可以使用:
IConnectionInfo oldConnInfo = new ConnectionInfo();
IConnectionInfo newConnInfo = new ConnectionInfo();
// If this connection needed parameters, we would use this field.
com.crystaldecisions.sdk.occa.report.data.Fields pFields = null;
try{
// Assign the old Connection info to the reports current info
//DatabaseController dbController = rptClient.getDatabaseController();
oldConnInfo=dbController.getConnectionInfos(null).getConnectionInfo(0);
com.crystaldecisions.sdk.occa.report.lib.PropertyBag boPropertyBag1 = new com.crystaldecisions.sdk.occa.report.lib.PropertyBag();
boPropertyBag1.put("JDBC Connection String","...");
boPropertyBag1.put("Server Type","...");
boPropertyBag1.put("Database Type","...");
boPropertyBag1.put("Database Class Name","...");
boPropertyBag1.put("Use JDBC","...");
boPropertyBag1.put("Connection URL","...");
boPropertyBag1.put("Database DLL","...");
// Assign the properties to the connection info
newConnInfo.setAttributes(boPropertyBag1);
// Set the DB Username and Pwd
newConnInfo.setUserName("...");
newConnInfo.setPassword("...");
// The Kind of connectionInfos is SQL
newConnInfo.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(oldConnInfo, newConnInfo, pFields, replaceParams);
}catch(ReportSDKException rse){
...
}
在上面的代码段中传递适当的值。很抱歉,这使用了com.crystaldecisions.sdk.occa.report API
希望这有帮助…您可以使用eclipse版本进行crystal report开发。您可以从那里下载eclipse插件 您可以找到一个很好的示例,从使用Java开发crystal reports开始
您可以找到与crystel reports相关的答案,其中说明了有关使用Java开发crystal reports的所有必要信息。我不知道Swing在这方面起到什么作用,除了您可能需要注意在后台线程中调用此代码外,否则创建报告的过程与使用Java开发crystal reports相同从Swing GUI和控制台程序都可以。我真的不明白。对不起,除了数据库部分的动态更改之外,一切都很好。谢谢你的回答。oldConnInfo和newConnInfo都是java.sql.Connection对象吗?我是否需要像我那样更改所有表的属性?如果不需要,我如何获得IConnectionIn来自reportclientdocument的fo?您可以使用以下命令获取旧连接对象:IConnectionInfo oldConnInfo=dbController.getConnectionInfo(null)。getConnectionInfo(0);还要为新连接创建另一个IConnectionInfo对象,并为各种属性分配值。我将编辑上述答案以包含这些详细信息。感谢您的帮助。我尝试了此操作,但出现了servernotfound错误。这可能是因为我没有crystal reports server。我只有标准crystal report designer安装在我的电脑中。:(我不认为它与Crystal Reports Server有任何关系…bcoz我也只有CR designer,它对我来说工作得很好。。。