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