請幫忙。我正在開發一個可以打開使用水晶報告xi進行報告的swing應用程序。我試圖做的是打開一個報告並將連接信息傳遞給該報告,以便我可以動態更改報告的數據庫。但由於某種原因,它不起作用,並且報告仍會從數據庫中產生最初設置的信息。有人能告訴我我做錯了什麼嗎?順便說一句,當我嘗試使用com.crystaldecisions.sdk.occa.report.application.ReportClientDocument,我得到一個服務器未找到錯誤。但是當我嘗試使用import com.crystaldecisions.reports.sdk.ReportClientDocument;它不工作。我不確定報表服務器是什麼,我不認爲我將它安裝在我的電腦上。請幫忙。這是我的代碼:如何使用java swing在水晶報表運行時切換數據庫連接
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);
糟糕。我的錯。但實際上,如果我使用此代碼與更正的propertyBag,我得到一個serverNotFound錯誤。對此有何幫助? – John
也許你在DBConnect有問題。 – tibtof
我的DBConnect工作正常。我有其他類依賴於它。這是確切的錯誤消息: com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException:沒有指定服務器.----錯誤代碼:-2147217390錯誤代碼名稱:serverNotFound。每當我使用導入com.crystaldecisions.sdk.occa.report.application.ReportClientDocument而不是com.crystaldecisions.reports.sdk.ReportClientDocument – John