birt报表动态切换数据源解决方案_第1页
birt报表动态切换数据源解决方案_第2页
birt报表动态切换数据源解决方案_第3页
birt报表动态切换数据源解决方案_第4页
birt报表动态切换数据源解决方案_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Birt报表动态切换数据源解决方案陈鸿编写(一) 通过 library实现连接数据库管理1. 理解library(库):可视化的报表开发环境。可以理解为,在使用创建报表的时候有很多的报表资源都会重复的使用,这样为了方便管理,可以将这些部分放在library文件里,这样其它报表只要是引用这些library文件即可。同时也方便了管理,例如当修改数据源的时候,只要修改包含数据源的library文件就可以了,而不必去一个个修改其它的报表文件。这些库可包含任何报表元素,比如样式、数据源、报表条目、脚本等等。2. 创建library:增加到应用中用于运行报表,并可以把报表以各种形式导出,如Excel、HTML分页格式、PDF、RTF等。A 选新建LibraryB 可以看到新类似于创建报表文件的界面C 选择所需的驱动,并添加合法的数据源信息。D 创建数据源完成后,也可以继续创建数据集。3. 使用libraryA 下面进行报表文件的制作,制作过程中会用到这个library文件。新建一个报表文件。在视图里选择Library Explorer,右击,添加刚才新建好的Library文件。添加完成后记得点上面的刷新。B 进行引用,首先确保Data Explorer和Library Explorer同时在界面里显示,之后便是将Library 里的我们要用的数据拖拽到Data Explorer 自己的报表Data sources中。便完成了引用数据源。如果Library中还有其它我们要引用的部分也是同样去操作。4. 在java中修改birt报表library的数据源/ 修改.rptlibrary内的数据源信息 public void setDataSource(String rptdesignPath) DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; InputStream is = null; String datasource = null; Document doc = null; String EncodePsd = null; try db = dbf.newDocumentBuilder(); try is = new FileInputStream(rptdesignPath); try doc = db.parse(is); is.close(); catch (SAXException e) toPrint(SAXException); return; catch (IOException e) toPrint(Cant read file + rptdesignPath + ); return; catch (FileNotFoundException e) toPrint(Cant found file + rptdesignPath + ); return; catch (ParserConfigurationException e) / TODO Auto-generated catch block toPrint(ParserConfigurationException); return; / 查找data-sources信息 NodeList nodeList = doc.getElementsByTagName(data-sources); for (int i = 0; i nodeList.getLength(); i+) Element e = (Element) nodeList.item(i); NodeList properties = e.getChildNodes(); if (properties != null) / 得到oda-data-source部分信息 Node property = properties.item(1); for (Node node = property.getFirstChild(); node != null; node = node .getNextSibling() / 得到driver、url、username、password四项的值,并重新设置 if (node.getNodeName().equals(property) | node.getNodeName().equals(encrypted-property) String name = node.getAttributes().getNamedItem(name) .getNodeValue(); if (name.equals(odaDriverClass) node.getFirstChild().setNodeValue(driver); else if (name.equals(odaURL) node.getFirstChild().setNodeValue(url); else if (name.equals(odaUser) node.getFirstChild().setNodeValue(username); else if (name.equals(odaPassword) / 对密码进行base64编码 EncodePsd = (new sun.misc.BASE64Encoder() .encode(password.getBytes(); / System.out.println(*EncodePsd: / +EncodePsd); node.getFirstChild().setNodeValue(EncodePsd); / 写入指定的文件中 writeToXml(doc, rptdesignPath); / write to xml public void writeToXml(Document doc, String rptdesign) try OutputStream fileoutputStream = new FileOutputStream(rptdesign); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(fileoutputStream); transformer.transform(source, result); fileoutputStream.close(); catch (Exception e) toPrint(Cant write to file:

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论