gj122512597 2015-02-12 11:21
浏览 2671
已结题

crystal report 水晶报表 可以直接在Java application

现在做个项目需要在Java application 中直接调用crystal report的API ,不用JNDI的方式链接数据库,不用JSP,就是说直接在Java application 的main方法里面去实现crystal report的链接数据库更能,请问有什么办法吗?

以下是我通过JNDI的方法实现的代码,可以正常运行,现在求不用JNDI的方法:
public void runReportUsingSql() throws Exception {
String jndiName ="fams_system";
String reportPath ="C:/MyDevelopTools/FARMS/WebApp/WebContent/reporting/wizard/AT020.RPT";
final String sql="SELECT SYSTEM_TYPE_MSTR.ID_TYPE, SYSTEM_TYPE_MSTR.DESC_TYPE, SYSTEM_TYPE_MSTR.NOTE_TYPE, SYSTEM_TYPE_MSTR.NAME_SUPR, SYSTEM_CLAS_MSTR.ID_CLAS, SYSTEM_CLAS_MSTR.DESC_CLAS, SYSTEM_CLAS_MSTR.NOTE_CLAS, SYSTEM_CLAS_MSTR.ID_PARA, SYSTEM_CLAS_MSTR.CODE_AUTH, SYSTEM_CLAS_MSTR.CODE_XREF FROM FAMSADMN.SYSTEM_TYPE_MSTR SYSTEM_TYPE_MSTR, FAMSADMN.SYSTEM_CLAS_MSTR SYSTEM_CLAS_MSTR WHERE SYSTEM_TYPE_MSTR.ID_TYPE = SYSTEM_CLAS_MSTR.ID_TYPE AND SYSTEM_TYPE_MSTR.ID_TYPE = 'MEMBER' AND SYSTEM_CLAS_MSTR.ID_CLAS IN ('DADADADA') ORDER BY SYSTEM_CLAS_MSTR.ID_CLAS ASC, SYSTEM_TYPE_MSTR.ID_TYPE ASC FOR FETCH ONLY";

    reportClientDoc.setReportAppServer(ReportClientDocument.inprocConnectionString);
    reportClientDoc.open(reportPath, OpenReportOptions._openAsReadOnly);

    ITable table = reportClientDoc.getDatabaseController().getDatabase().getTables().getTable(0);

    IConnectionInfo oldConnectionInfo = new ConnectionInfo();
    IConnectionInfo newConnectionInfo = new ConnectionInfo();

    // Assign the old Connection info to the reports current info
    DatabaseController dbController = reportClientDoc.getDatabaseController();
    oldConnectionInfo = dbController.getConnectionInfos(null).getConnectionInfo(0);

// Create a new propertybag for the new location
PropertyBag propertyBag = oldConnectionInfo.getAttributes();
propertyBag.put("Use JDBC", true);
propertyBag.put("Use JNDI", true);
propertyBag.put("JNDI Datasource Name", jndiName);
newConnectionInfo.setAttributes(propertyBag);
newConnectionInfo.setKind(ConnectionInfoKind.SQL);

    Fields pFields = null;
    if (table instanceof CommandTable) {

// ((CommandTable) table).setCommandText(sql);
}

    int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;
    reportClientDoc.getDatabaseController().replaceConnection(oldConnectionInfo, newConnectionInfo, pFields,
            replaceParams);

    try{
         String result="C:/MyDevelopTools/ReportResult.pdf";
            Fields fields = reportClientDoc.getDataDefController().getDataDefinition().getParameterFields();
            for (int i = 0; i < fields.size(); i++) {
               IParameterField paramField = (IParameterField)fields.getField(i);
               String name = paramField.getName();
                          reportClientDoc.getDataDefController().getParameterFieldController().setCurrentValue("", name , new String("guojun"));
            }


     ByteArrayInputStream byteInput = (ByteArrayInputStream) reportClientDoc
             .getPrintOutputController().export(ReportExportFormat.PDF);
     byte byteArray[] = new byte[byteInput.available()];
     File file = new File(result);
     FileOutputStream fileOut = new FileOutputStream(file);
     ByteArrayOutputStream byteOut = new ByteArrayOutputStream(byteInput
             .available());
     int x = byteInput.read(byteArray, 0, byteInput.available());
     byteOut.write(byteArray, 0, x);
     byteOut.writeTo(fileOut);
     byteOut.close();
     fileOut.close();

// reportClientDoc.close();
}
catch (Exception e) {
throw e;
}
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 易语言把MYSQL数据库中的数据添加至组合框
    • ¥20 求数据集和代码#有偿答复
    • ¥15 关于下拉菜单选项关联的问题
    • ¥20 java-OJ-健康体检
    • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
    • ¥15 使用phpstudy在云服务器上搭建个人网站
    • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
    • ¥15 vue3+express部署到nginx
    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况