-- 作者:lolo6062
-- 发布时间:4/26/2005 8:08:00 AM
-- [求助] 请大家指点一下错误
import java.sql.*; import java.io.*; import org.jdom.output.*; import java.*; import org.jdom.*; import org.jdom.input.*; class Revert { public void Revert() { try{ java.sql.Connection con=null; Document doc=null; String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs"; String user="sa"; String password=""; java.lang.String strConn; try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); con=DriverManager.getConnection (url,user,password); }catch(ClassNotFoundException e) {System.out.println("can`t found the class!");} SAXBuilder sb = new SAXBuilder(); //从文件构造一个Document,因为XML文件中已经指定了编码,所以这里不必了 try{ doc = sb.build(new FileInputStream("d:\\rmi\\a.xml")); }catch(FileNotFoundException e) {System.out.println("File not found!");} catch(org.jdom.JDOMException e ) {System.out.println("jdomwrong");} catch(IOException e) {System.out.println("IO wrong");} //得到根元素“student列表” Element root = doc.getRootElement(); //得到根元素“student列表”所有子元素的集合 java.util.List student = root.getChildren(); //得到“_student表”元素 Element tables; //取得所有“_student表”子元素的集合 java.util.List table; //得到“student纪录”元素 Element record; String sql; Statement stmt=con.createStatement(); int j; //student tables=(Element)student.get(0); table=tables.getContent(); sql="delete from student"; stmt.executeUpdate(sql); for(j=0;j<table.size();j++) { record=(Element)table.get(j); sql="insert into student values(" + record.getChildTextTrim("id") + ",'"; sql=sql + record.getChildTextTrim("name") + "')"; stmt.executeUpdate(sql); } } catch(SQLException e) {} System.out.println("从XML到数据库的导入完毕!"); } public static void main(String args[]){ Revert mxf = new Revert(); mxf.Revert(); } } D:\rmi>javac Revert.java Revert.java:60: incompatible types found : java.lang.String required: java.util.List table=tables.getContent(); ^ Note: Revert.java uses or overrides a deprecated API. Note: Recompile with -deprecation for details. 1 error
|