我有這樣的代碼如何在java swing應用程序中打開水晶報表?
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));
什麼進出口試圖做的就是打開報表,並通過該連接信息,以該報告,這樣我可以動態改變報告的數據庫,但由於某種原因,它不工作並且報告仍然會從最初設置的數據庫中生成信息。有人能告訴我我做錯了什麼嗎?這是一個擺動應用程序,我正在使用水晶報表XI。 Btw我使用com.crystaldecisions.reports.sdk.ReportClientDocument而不是com.crystaldecisions.sdk.occa.report.application.ReportClientDocument,因爲當我使用另一個,我得到一個無法找到服務器錯誤。請幫忙。
我不明白Swing是如何真正扮演這個角色的,除非您可能需要小心地在後臺線程中調用此代碼,否則創建報告的方式與從Swing GUI執行的方式相同一個控制檯程序。 –
我真的沒有得到。抱歉。除了數據庫部分的動態變化以外,一切都很好。 – John