Visualizzazione dei risultati da 1 a 3 su 3

Discussione: [java] jaxp o db?

  1. #1

    [java] jaxp o db?

    Ciao a tutti.Premetto che di xml me ne intendo poco.
    Ho un'idea e vorrei sapere da voi se sto facendo una cosa corretta oppure no.
    Ho realizzato un programma in java che ogni minuto interroga un database per recuperare un elenco di utenti,per poi mandare avvisi a questo elenco.Per aggiungere e/o modificare questi utenti esiste una pagina php che manipola i record.
    Ora pensavo che al posto di fare interrogare dal mio programma java continuamente la tabella, potrei esportare questi record di utenti su un file xml, per poi leggere il file tramite jaxp.Sono riuscito tramite il seguente codice a far leggere da java un file xml.
    codice:
    public class DOMTest { 
    
        public static void main(String args[]) { 
    
            if (args.length != 1) { 
                System.err.println("Usage: java DOMTest xmlfilename"); 
                System.exit(1); 
            } 
    
            try { 
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
                DocumentBuilder db = dbf.newDocumentBuilder(); 
    
                Document doc = db.parse(new File(args[0])); 
                NodeList nl = doc.getElementsByTagName("book"); 
                Element e; 
                Collection c = new Vector(); 
    
                // fill collection with book objects 
                for (int i=0; i<nl.getLength(); i++) { 
                    e = (Element)nl.item(i); 
                    c.add( new Book(e) ); 
                } 
    
                // print out collection content 
                Iterator    i = c.iterator(); 
                Book        book; 
                while (i.hasNext()) { 
                    book = (Book)i.next(); 
                    System.out.println("Author: " + book.getAuthor() + " - title: " + book.getTitle()); 
                } 
    
            } 
            catch (IOException ioe) { 
                System.err.println("Input/Output error: " + ioe.getMessage()); 
                System.exit(1); 
            } 
            catch (SAXParseException spe) { 
                System.err.println("Parsing exception for entity " + spe.getPublicId() + " at line: " + spe.getLineNumber() + " column: " + spe.getColumnNumber()); 
                System.exit(1); 
            } 
            catch (SAXException se) { 
                System.err.println("General SAX exception: " + se.getMessage()); 
                System.exit(1); 
            } 
            catch (ParserConfigurationException pce) { 
                System.err.println("General SAX exception: " + pce.getMessage()); 
                System.exit(1); 
            } 
            catch (FactoryConfigurationError fce) { 
                System.err.println("Configuration error: " + fce.getMessage()); 
                System.exit(1); 
            } 
        } 
    }
    Secondo voi mi conviene leggere i dati dal db mysql o leggerli dall'xml?
    é una buona idea processare tutto tramite file xml?

  2. #2
    Per me sono due idee alternative, o leggi dal DB, o leggi dall'XML.
    Non vedo particolari vantaggi / svantaggi per l'una o l'altra soluzione.

  3. #3
    Non potrei usare l'xml come cache? Cosa mi serve l'xml allora???

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.