xml基础教程2版第7章的代码

xml基础教程2版第7章的代码

ID:14405532

大小:66.50 KB

页数:6页

时间:2018-07-28

xml基础教程2版第7章的代码_第1页
xml基础教程2版第7章的代码_第2页
xml基础教程2版第7章的代码_第3页
xml基础教程2版第7章的代码_第4页
xml基础教程2版第7章的代码_第5页
资源描述:

《xml基础教程2版第7章的代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、第7章XML与数据库7.3连接数据库例子1InsertAndQuery.javaimportjava.sql.*;publicclassInsertAndQuery{publicstaticvoidmain(Stringargs[]){Connectioncon;Statementsql;ResultSetrs;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundExceptione){System.out.println(""+e);}try{con=DriverManager.

2、getConnection("jdbc:odbc:company","","");sql=con.createStatement();sql.executeUpdate("INSERTINTOpersonVALUES('a1004','张三','1995-12-12',3000)");sql.executeUpdate("INSERTINTOpersonVALUES('a1005','李四','1996-09-10',5000)");rs=sql.executeQuery("SELECT*FROMperson");while(rs.next()){Stringnumb

3、er=rs.getString(1);Stringname=rs.getString(2);Datebirth=rs.getDate(3);doublesalary=rs.getDouble(4);System.out.println(number+","+name+","+birth+","+salary);}con.close();}catch(SQLExceptione){163System.out.println(e);}}}7.4XML至数据库例子2example7_2.xml<雇员列表

4、><雇员><雇员号>A1006<姓名>王经路<出生日期>1995-11-11<薪水>6789<雇员><雇员号>A1007<姓名>赵懂知<出生日期>1995-06-28<薪水>5673XMLToDatabase.javaimportjavax.xml.xpath.*;importorg.xml.sax.*;importorg.w3c.dom.*;importjava.sql.*;publicclassXMLToDatabase{publicsta

5、ticvoidmain(Stringargs[]){Connectioncon=null;Statementsql=null;ResultSetrs=null;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");163}catch(Exceptione){System.out.println(""+e);}try{con=DriverManager.getConnection("jdbc:odbc:company","","");sql=con.createStatement();XPathFactoryxPathFac

6、tory=XPathFactory.newInstance();XPathxPath=xPathFactory.newXPath();InputSourcesource=newInputSource("example9_2.xml");Stringpath="/雇员列表/雇员";NodeListnodeList=(NodeList)xPath.evaluate(path,source,XPathConstants.NODESET);intsize=nodeList.getLength();for(inti=0;i

7、员列表/雇员["+m+"]/*/text()";nodeList=(NodeList)xPath.evaluate(path,source,XPathConstants.NODESET);intlength=nodeList.getLength();String[]a=newString[length];for(intk=0;k

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。