import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; import java.sql.*; import java.io.*; import org.w3c.dom.*; public class UusDokument{ public static void main(String argumendid[]) throws Exception{ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn=DriverManager.getConnection( "jdbc:odbc:yhendus1", "", ""); Statement st=cn.createStatement(); String lause="SELECT * FROM raamatud;"; ResultSet rs=st.executeQuery(lause); Document d=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element juur=d.createElement("raamatud"); d.appendChild(juur); while(rs.next()){ Element e=d.createElement("raamat"); juur.appendChild(e); Element p=d.createElement("pealkiri"); p.appendChild(d.createTextNode(rs.getString("pealkiri"))); e.appendChild(p); Element a=d.createElement("autor"); a.appendChild(d.createTextNode(rs.getString("autor"))); e.appendChild(a); } Transformer t=TransformerFactory.newInstance().newTransformer(); t.transform(new DOMSource(d), new StreamResult(new FileOutputStream("raamatud.xml"))); }catch(Exception viga){ viga.printStackTrace(); } } }