pt.moredata.xml.db
Class DbToXML

java.lang.Object
  extended bypt.moredata.xml.db.DbToXML

public class DbToXML
extends java.lang.Object

DbToXML is a class that provides a static method to convert an SQL statement in a string to a XML Element in JDOM fashion. It also should work with our DAOs and Java's ResultSets.

Here is an example of how it can be used:

 public static void main( String[] args ) {

    try {
       // Obtain a conection to a DB
       Connection dbCon = getConnection2DB();

       // Obtain the XML Element with the database data and put it in a Document
       Document myDoc = new Document(JDOMconverter("SELECT * FROM esisit ORDER BY asitdes", 
                                                          dbCon, "esisit", "row"));

       // Format the Document and show it
       XMLOutputter outputter = new XMLOutputter("  ", true);
       outputter.setEncoding("ISO-8859-1");
       outputter.output(myDoc, System.out);
    } catch (Exception e) {
       System.out.println("Error: "+e.getMessage());
    }
 }
 

Author:
ferdez em moredata ponto pt

Constructor Summary
DbToXML()
          Creates a new instance of DbToXML - no need for this - do not use
 
Method Summary
static org.jdom.Element JDOMconverter(DataAccessObject dao, java.lang.String elementName, java.lang.String rowDesignator)
          Returns a JDOM Element containing the contents of the DAO
static org.jdom.Element JDOMconverter(java.sql.ResultSet rs, java.lang.String elementName, java.lang.String rowDesignator)
          Returns a JDOM Element containing the contents of the ResultSet, assuming that it has already executed the query
static org.jdom.Element JDOMconverter(java.lang.String SQLCommand, java.sql.Connection DBConn, java.lang.String elementName, java.lang.String rowDesignator)
          Returns a JDOM Element containing the result of the query that is passed as a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbToXML

public DbToXML()
Creates a new instance of DbToXML - no need for this - do not use

Method Detail

JDOMconverter

public static org.jdom.Element JDOMconverter(java.lang.String SQLCommand,
                                             java.sql.Connection DBConn,
                                             java.lang.String elementName,
                                             java.lang.String rowDesignator)
                                      throws java.sql.SQLException
Returns a JDOM Element containing the result of the query that is passed as a string

Parameters:
SQLCommand - The query in SQL
DBConn - The connection to the database
elementName - The name of the Element in the XML structure
rowDesignator - The name of the row Elements in the XML structure
Returns:
JDOM Element
Throws:
java.sql.SQLException - Yes it does. :-)

JDOMconverter

public static org.jdom.Element JDOMconverter(DataAccessObject dao,
                                             java.lang.String elementName,
                                             java.lang.String rowDesignator)
                                      throws java.sql.SQLException
Returns a JDOM Element containing the contents of the DAO

Parameters:
dao - The DAO to be converted
elementName - see above
rowDesignator - see above
Returns:
see above
Throws:
java.sql.SQLException - Yup!

JDOMconverter

public static org.jdom.Element JDOMconverter(java.sql.ResultSet rs,
                                             java.lang.String elementName,
                                             java.lang.String rowDesignator)
                                      throws java.sql.SQLException
Returns a JDOM Element containing the contents of the ResultSet, assuming that it has already executed the query

Parameters:
rs - The ResultSet that is to be converted into XML
elementName - see above
rowDesignator - see above
Returns:
see above
Throws:
java.sql.SQLException - Ya!