欢迎来到天天文库
浏览记录
ID:24340242
大小:54.50 KB
页数:3页
时间:2018-11-13
《java-读取xml文件中sqlserver数据源配置(sax)--》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、JAVA/读取XML文件中SQLSERVER数据源配置(sax)>>XML文件:mssql.xml<?xmlversion="1.0"encoding="UTF-8"?><reportenv><datasource><servername>localhost</servername><serverport>1433</serverport><databasename>nee><username>sa</username><passportjav
2、a.util.Properties;importorg.xml.sax.Attributes;importorg.xml.sax.SAXException;importorg.xml.sax.helpers.DefaultHandler;classConfigParserextendsDefaultHandler{//定义一个Properties用来存放属性值privatePropertiesprops;privateStringcurrentSet;privateStringcurrentName;privateStringBuffercurrentValue=neent
3、(Stringuri,StringlocalName,StringqName,Attributesattributes)throe=qName;}//这里是将<xxx></xxx>之间的值加入到currentValuepublicvoidcharacters(char[]ch,intstart,intlength)throent(Stringuri,StringlocalName,StringqName)throe.toLo());}}XML配置文件读取处理:ParseXML.javapackage.onechen.data.config;impor
4、tjava.util.Properties;importjavax.xml.parsers.SAXParser;importjavax.xml.parsers.SAXParserFactory;classParseXML{//定义一个Properties用来存放属性值privatePropertiesprops;publicPropertiesgetProps(){returnthis.props;}publicvoidparse(Stringfilename)throespaceAl联系起来,开始解析parser.parse(filename,handler);//获取解
5、析成功后的属性props=handler.getProps();}finally{12下一页>>>>这篇文章来自..,。factory=null;parser=null;handler=null;}}}读取XML配置文件:ReadConfigXml.javapackage.onechen.data.config;importjava.util.Properties;publicclassReadConfigXml{9731248:上一页12>>>>这篇文章来自..,。
此文档下载收益归作者所有