欢迎来到天天文库
浏览记录
ID:37925878
大小:35.50 KB
页数:7页
时间:2019-06-02
《Java+XML将数据导入SQL Server中》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Stringpassword=null;} publicStringgetUrl(){returnurl;} publicStringgetPassword(){returnpassword;} publicvoidsetDbClass(Stringstr){dbClass=str;} publicvoidsetUrl(Stringstr){url=str;} publicvoidsetUsername(Stringstr){username=str;} publicvoidsetPassword(Stringstr){password=str;Java+XML将数
2、据导入SQLServer中 文件ConnPara.java,表示以类形式表示的数据库连接参数。publicclassConnPara{ StringdbClass=null; Stringurl=null; Stringusername=null; Stringpassword=null; publicConnPara(){} publicConnPara(StringpdbClass,Stringpurl,Stringpusername,Stringppassword) { dbClass=pdbClass; url=purl; username=puse
3、rname; password=ppassword; } publicStringgetDbClass(){returndbClass;} publicStringgetUrl(){returnurl;} publicStringgetUsername(){returnusername;} publicStringgetPassword(){returnpassword;} publicvoidsetDbClass(Stringstr){dbClass=str;} publicvoidsetUrl(Stringstr){url=str;} publicvoidse
4、tUsername(Stringstr){username=str;} publicvoidsetPassword(Stringstr){password=str;}} 文件DbXmlParser.java封装了对xml文件的操作。importjavax.xml.parsers.*;importorg.w3c.dom.*;importorg.xml.sax.*;importjava.io.*;publicclassDbXmlParser{ staticStringxmlfile; publicDbXmlParser(Stringfilename) { xmlfi
5、le=filename; } publicstaticElementloadDocument() { try { //工厂 DocumentBuilderFactorydcfactory=DocumentBuilderFactory.newInstance(); //文档构造器 DocumentBuilderdb=dcfactory.newDocumentBuilder(); //构造的文档 Documentdoc=db.parse(xmlfile); //根元素 Elementroot=doc.getDocumentElemen
6、t(); returnroot; }catch(ParserConfigurationExceptione){ System.out.println("ParserConfigurationException"); e.printStackTrace(); }catch(IOExceptione){ System.out.println("IOException"); e.printStackTrace(); }catch(SAXExceptione){ System.out.println("SAXException"); e.p
7、rintStackTrace(); }catch(Exceptione){ e.printStackTrace(); } returnnull; } publicConnParagetSource() { Elementroot=loadDocument(); if(root==null){returnnull;} NodeListnodes=root.getElementsByTagName("source"); if(nodes.getLength()>0) { Nodenode=nodes.item(0); Stringconn
此文档下载收益归作者所有