栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

导出JasperReports查询结果

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

导出JasperReports查询结果

首先,我觉得这很不对劲,但是有可能减去JasperReports来执行查询。

JasperReport report = (JasperReport) JRLoader.loadObject(inStream);//this is the actual query in the reportJRQuery query = report.getMainDataSet().getQuery;//once here you get the entire sql string, this will have any parameters replaced with //the '?' characterString queryString = query.getText();//now start building your prepared statement, I am assuming you already have your//connection in the conn variablePrepararedStatment statement = con.prepareStatement(queryString);//almost there, need to set the parameters//the sql query is broke up into chunks inside the JRQuery. The chunks have types //that are  either text, parameter, or parameter clause. We care about parameter, //not sure what parameter clause would be to be honestint index = 0; //this is the index to set the parameter at in the statementfor (JRQueryChunk chunk : query.getChunks()){     if (chunk.getType() == JRQueryChunk .TYPE_PARAMETER){         statement.setObject(index, params.get(chunk.getText()));         index = index + 1;     }}//then execute the queryResultSet results = statement.executeQuery();

注意:
这里没有错误检查,您应该添加它。也不确定这样做是否是个好主意。最好将查询从报告中移出,然后完全移到Java代码中。然后只需将ResultSet作为数据源传递,就可以了。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/610285.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号