




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
String password=null;public String getUrl()return url;public String getPassword()return password;public void setDbClass(String str) dbClass=str;public void setUrl(String str) url=str;public void setUsername(String str)username=str;public void setPassword(String str)password=str; Java+XML将数据导入SQL Server中 文件ConnPara.java,表示以类形式表示的数据库连接参数。public class ConnParaString dbClass=null;String url=null;String username=null;String password=null; public ConnPara() public ConnPara(String pdbClass,String purl,String pusername,String ppassword)dbClass=pdbClass;url=purl;username=pusername;password=ppassword; public String getDbClass()return dbClass;public String getUrl()return url;public String getUsername()return username;public String getPassword()return password;public void setDbClass(String str) dbClass=str;public void setUrl(String str) url=str;public void setUsername(String str)username=str;public void setPassword(String str)password=str; 文件DbXmlParser.java封装了对xml文件的操作。 import javax.xml.parsers.*;import org.w3c.dom.*;import org.xml.sax.*;import java.io.*;public class DbXmlParser static String xmlfile;public DbXmlParser(String filename)xmlfile=filename;public static Element loadDocument()try/工厂DocumentBuilderFactory dcfactory=DocumentBuilderFactory.newInstance();/文档构造器DocumentBuilder db=dcfactory.newDocumentBuilder();/构造的文档Document doc=db.parse(xmlfile);/根元素Element root=doc.getDocumentElement();return root;catch( ParserConfigurationException e)System.out.println(ParserConfigurationException);e.printStackTrace();catch(IOException e) System.out.println(IOException );e.printStackTrace();catch(SAXException e) System.out.println(SAXException );e.printStackTrace();catch(Exception e) e.printStackTrace();return null;public ConnPara getSource()Element root=loadDocument();if( root=null) return null; NodeList nodes=root.getElementsByTagName(source);if(nodes.getLength()0) Node node=nodes.item(0);String connclass=getChildElementValue(node,class);String url=getChildElementValue(node,url);String username=getChildElementValue(node,user);String password=getChildElementValue(node,password);return new ConnPara(connclass,url,username,password);return null; public ConnPara getDest()Element root=loadDocument();if( root=null) return null;NodeList nodes=root.getElementsByTagName(dest);if(nodes.getLength()0) Node node=nodes.item(0);String connclass=getChildElementValue(node,class);String url=getChildElementValue(node,url);String username=getChildElementValue(node,user);String password=getChildElementValue(node,password);return new ConnPara(connclass,url,username,password);return null; /得到子元素的值private String getChildElementValue(Node node,String subTagName)String returnString = ;if(node != null)NodeList children = node.getChildNodes();for(int innerLoop = 0; innerLoop children.getLength(); innerLoop+)Node child = children.item(innerLoop);if(child = null | child.getNodeName() = null | !child.getNodeName().equals
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 初级会计送分试题及答案
- 绿色木材标准-洞察与解读
- 2025宝山社区考试真题及答案
- 计量员人员面试题及答案
- 岳阳八中模拟考试题及答案
- 中国海油模拟考试题及答案
- 2025年超市员工培训试卷及答案
- 芒果产业现状与发展路径探讨
- 初中历史政治试题及答案
- 2025年学生体育考试试题及答案
- 围墙新建及改造工程施工组织设计(技术标)
- 房屋建筑学民用建筑构造概论
- 政策议程多源流模型分析
- 蓝点网络分账解决方案
- GB/T 22315-2008金属材料弹性模量和泊松比试验方法
- GB/T 17980.37-2000农药田间药效试验准则(一)杀线虫剂防治胞囊线虫病
- 血管活性药物(ICU)课件
- 旅游饭店服务技能大赛客房服务比赛规则和评分标准
- “手电筒”模型-高考数学解题方法
- GB∕T 2980-2018 工程机械轮胎规格、尺寸、气压与负荷
- TTAF 068-2020 移动智能终端及应用软件用户个人信息保护实施指南 第8部分:隐私政策
评论
0/150
提交评论