背景知识:
1. 水晶 表主要用于设计和产生 表, 很多企业级系统都可以拿来集成,使得系统数据展示给客户
ReportClientDocument clientDoc = new ReportClientDocument();
clientDoc.setReportAppServer(ReportClientDocument.inprocConnectionString);
clientDoc.open(reportPath, OpenReportOptions._openAsReadOnly);
ITable table = clientDoc.getDatabaseController().getDatabase().getTables().getTable(0);
IConnectionInfo oldConnectionInfo = new ConnectionInfo();
IConnectionInfo newConnectionInfo = new ConnectionInfo();
DatabaseController dbController = clientDoc.getDatabaseController();
oldConnectionInfo = dbController.getConnectionInfos(null).getConnectionInfo(0);
1.通过JNDI
PropertyBag newPropertyBag = new PropertyBag();
propertyBag.put(“Trusted_Connection”, “false”);
propertyBag.put(“Server Type”, “JDBC (JNDI)”);
propertyBag.put(“Use JDBC”, true);
propertyBag.put(“JNDIOptionalName”, jndiName);
propertyBag.put(“Use JNDI”, true);
propertyBag.put(“JNDI Data Source Name”, jndiName);
propertyBag.put(“JNDI Datasource Name”, jndiName);
newConnectionInfo.setAttributes(newPropertyBag);
newConnectionInfo.setKind(ConnectionInfoKind.SQL);
2.直接连接数据库 需要DB URL和DB用户名密码
PropertyBag newPropertyBag = new PropertyBag();
newPropertyBag.put(“Trusted_Connection”, “false”);
newPropertyBag.put(“PreQEServerName”, “jdbc:microsoft:sqlserver://
newPropertyBag.put(“Server Type”, “JDBC (JNDI)”);
newPropertyBag.put(“Database DLL”, “crdb_jdbc.dll”);
newPropertyBag.put(“Database Class Name”, “com.microsoft.jdbc.sqlserver.SQLServerDriver”);
newPropertyBag.put(“Use JDBC”, “true”);
newPropertyBag.put(“Server Name”, “jdbc:microsoft:sqlserver://
newPropertyBag.put(“Connection URL”,”jdbc:microsoft:sqlserver://
newConnectionInfo.setUserName(
newConnectionInfo.setPassword(
newConnectionInfo.setAttributes(newPropertyBag);
newConnectionInfo.setKind(ConnectionInfoKind.SQL);
3.通过Result Set
ResultSet rs = …;
String tableAlias = table.getAlias();
int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;
if (“Command”.equalsIgnoreCase(tableAlias.trim())) {
dbController.addDataSource(rs);
}else{
dbController.setDataSource(rs, tableAlias, “resultsetTable”);
}
水晶 表可以通过CrystalReportViewer 在前端展示
CrystalReportViewer viewer = new CrystalReportViewer();
viewer.setReportSource(reportSource);
viewer.setOwnPage(true);
viewer.setHasExportButton(true);
viewer.setHasToggleParameterPanelButton(false);
viewer.setPrintMode(CrPrintMode.PDF);
viewer.setHasRefreshButton(false);
viewer.setHasSearchButton(true);
viewer.setHasPrintButton(true);
……………..
也可以在后台生成PDF文件
ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) clientDoc.getPrintOutputController().export(ReportExportFormat.PDF);
记录于此 备用 有不对的地方 请指正
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!