水晶报表在java中使用,如何在运行时在水晶报表中使用java swing切换数据库连接...

Please help. I am developing a swing application that can open reports made using crystal reports xi. What Im trying to do is to open a report and pass the connection info to that report so that I can dynamically change the database of the report. But for some reason it is not working and the report still produces the information from the database that it was initially set up. Can someone please tell me what I did wrong? Btw when I try using com.crystaldecisions.sdk.occa.report.application.ReportClientDocument, I get a server not found error. But when I try to use import com.crystaldecisions.reports.sdk.ReportClientDocument; It's not working. I am not sure what a report server is and I dont think I set it up on my computer. Please help. Here is my code:

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

ReportClientDocument rpt = new ReportClientDocument();

rpt.open(reportPath+fileName, 0);

Fields fields = null;

IConnectionInfo connInfo = rpt.getDatabaseController().getConnectionInfos(null).getConnectionInfo(0);

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("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(innerProp);

connInfo.setPassword(DBConnect.getPassword());

connInfo.setUserName(DBConnect.getUsername());

int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;

rpt.getDatabaseController().replaceConnection(rpt.getDatabaseController().getConnectionInfos(null).getConnectionInfo(0), connInfo, fields, replaceParams);

解决方案

You are not using the properties added to propertyBag. You should either add the properties to innerProp, replacing propertyBag.put(...) with innerProp.put(...) or change connInfo.setAttributes(innerProp) to connInfo.setAttributes(propertyBag). I suggest the first approach.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值