chapter_005/src/main/java/xmlXsltJdbs/Optimization.java
private void safefilenumber1() {

        try {
            Statement statement = connection.createStatement();
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder;

            builder = factory.newDocumentBuilder();
            Document doc = builder.newDocument();
            Element rootElement = doc.createElementNS("", "entries");
            doc.appendChild(rootElement);

            ResultSet rs = statement.executeQuery("SELECT * FROM test");
            while (rs.next()) {
                rootElement.appendChild(getNewNode(doc, rs.getInt("field")));
            }
            rs.close();
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            StreamResult file = new StreamResult(new File(System.getProperty("user.dir") + "\\1.xml"));
            DOMSource xmlSource = new DOMSource(doc);
            transformer.transform(xmlSource, file);

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        }
        System.out.println("Save file 1.xml");
    }
/**
     * Create and safe file number one.
     */
Create and safe file number one.
Create and safe file number one .
private void safefilenumber1() {
        try {
            Statement statement = connection.createStatement();
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder;
            builder = factory.newDocumentBuilder();
            Document doc = builder.newDocument();
            Element rootElement = doc.createElementNS("", "entries");
            doc.appendChild(rootElement);
            ResultSet rs = statement.executeQuery("SELECT * FROM test");
            while (rs.next()) {
                rootElement.appendChild(getNewNode(doc, rs.getInt("field")));
            }
            rs.close();
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            StreamResult file = new StreamResult(new File(System.getProperty("user.dir") + "\\1.xml"));
            DOMSource xmlSource = new DOMSource(doc);
            transformer.transform(xmlSource, file);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        }
        System.out.println("Save file 1.xml");
    }
private void safefilenumber1 ( ) { try { Statement statement = connection . createStatement ( ) ; DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; DocumentBuilder builder ; builder = factory . newDocumentBuilder ( ) ; Document doc = builder . newDocument ( ) ; Element rootElement = doc . createElementNS ( "" , "entries" ) ; doc . appendChild ( rootElement ) ; ResultSet rs = statement . executeQuery ( "SELECT * FROM test" ) ; while ( rs . next ( ) ) { rootElement . appendChild ( getNewNode ( doc , rs . getInt ( "field" ) ) ) ; } rs . close ( ) ; TransformerFactory transformerFactory = TransformerFactory . newInstance ( ) ; Transformer transformer = transformerFactory . newTransformer ( ) ; StreamResult file = new StreamResult ( new File ( System . getProperty ( "user.dir" ) + "\\1.xml" ) ) ; DOMSource xmlSource = new DOMSource ( doc ) ; transformer . transform ( xmlSource , file ) ; } catch ( SQLException e ) { e . printStackTrace ( ) ; } catch ( ParserConfigurationException e ) { e . printStackTrace ( ) ; } catch ( TransformerConfigurationException e ) { e . printStackTrace ( ) ; } catch ( TransformerException e ) { e . printStackTrace ( ) ; } System . out . println ( "Save file 1.xml" ) ; }
Create and safe file number one.
Create and safe file number one .