2012-05-18 44 views
1

我有這樣的代碼,我在我的揮杆應用程序中使用:如何將連接從我的java swing應用程序傳遞到Crystal Reports XI?

ReportClientDocument rpt = new ReportClientDocument(); 
    rpt.open(reportPath+"APVendorList.rpt", 0); 
    rpt.getReportSource(); 


    ReportViewerBean viewer = new ReportViewerBean(); 
    viewer.init(new String[0], null, null, null); 
    //viewer.setHasGroupTree(false); 
    viewer.setReportSource(rpt.getReportSource()); 

的問題是,每當我嘗試使用JFrame的加載報告,它總是要求登錄憑據:

Database Logon: 
Server Name: Localhost 
Database Name: <blank and cannot be edited> 
User ID: 
Password: 

是有沒有辦法不輸入這些信息eveytime我查看報告?或者我可以只傳遞java.sql.Connection到它?此外,它似乎不知道要連接到哪個數據庫。請幫忙。

+0

* 「?如何通過從我的Java Swing應用程序連接到的Crystal Reports XI」 *可能就像你從命令行執行的一樣。 Swing對此有什麼要求? –

+0

糟糕!抱歉誤導性的標題。我想應該是,「如何將連接從我的Java swing應用程序傳遞給我的水晶報告」? – John

+0

相同的評論適用於建議的更改標題。還請注意它是Java&Swing,而不是java&swing。 –

回答

2

您可以設置的屬性值,像這樣:

ReportClientDocument clientDoc = new ReportClientDocument(); 
.... 
DatabaseController dbController=clientDoc.getDatabaseController(); 
IConnectionInfo ConnInfo = dbController.getConnectionInfos(null).getConnectionInfo(0); 
com.crystaldecisions.sdk.occa.report.lib.PropertyBag boPropertyBag1 = new com.crystaldecisions.sdk.occa.report.lib.PropertyBag(); 
// Set the properties for the connection 
boPropertyBag1.put("JDBC Connection String", connString); 
boPropertyBag1.put("Database Class Name", dbClassName); 
boPropertyBag1.put("Connection URL", connString); 
boPropertyBag1.put("Server", serverHost); 
.... 
// Assign the properties to the connection info 
ConnInfo.setAttributes(boPropertyBag1); 
// Set the DB Username and Pwd 
ConnInfo.setUserName(usrName); 
ConnInfo.setPassword(pwd); 

希望這有助於...

+0

感謝您的回答。我試過這個代碼,它的工作,一次。第一次運行後,我收到一條錯誤消息: com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException:沒有指定服務器。 ----錯誤代碼:-2147217390錯誤代碼名稱:serverNotFound 順便說一句檢查我有一個簡單的解決方案後級,它實際工作 ReportClientDocument RPT =新ReportClientDocument(); rpt.open(reportPath +「聯繫。 rpt「,0); rpt.getDatabaseController().logon(」username「,」password「); 是不是這個簡單代碼的結果 – John

+0

是的,我認爲是正確的.. 。 – ria

相關問題