Using java and extracting XML data through JDBC

Extracting data from a database through JDBC and creating an XML document from that data is simple logic. If you have already worked in creating an XML document using java, then the process getting data from a database through JDBC and creating an XML document is also easy.


_______________________________________________

The only difference is that you have to map the data that is got from the database to the XML elements that you are creating.

Creating an XML document can be done using the classes like DocumentBuilderFactory, DocumentBuilder, and Document. Using these three you can create a document object. The next step is to connect to your database through JDBC. This can be done very easily using a statement like,

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection db = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:mydb", "userid", "pwd");

Using a prepared statement and the resultset to get the query executed and getting the result is very easy and there are lots of examples on that part. For our issue, you have to create one ResultSetMetaData object. This object can be loaded with the resultsetmetadata using the getMetaData() of the resultset object.

Now you have to loop through the result set and get the column values and store them in a variable or an array. Then loop through the array and create text nodes and append them to the root node you have created for the Document object. You can find an example at http://www.ibm.com/developerworks/edu/x-dw-xextract-i.html.




_______________________________________________

FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

_______________________________________





| About Sequences and their attributes in Oracle10g | Accessing Remote data with Database Links in Oracle10g | A Guide to Iterative Processing with Loops in PL/SQL | A note on Dynamic SQL and its implementation in PL/SQL Application | Autonomous Transactions in Oracle – How to create and use if efficiently | Backup and Recovery – Best Practices in Oracle10g | Compiling Procedures, Functions and Packages during Application Development in Oracle10g | Introducing Publish-Subscribe Model in Oracle10g | Exploring Debugging Procedures in Oracle10g | External Procedures and their uses in Oracle10g | Guidelines for Locking Data in Oracle10g | How to customize an oracle10g Database using Database triggers | Specifying Constraints while creating table in Oracle10g to enhance Data Integrity |

 

 

FREE Subscription

Stay Current With the Latest Technology Developments Realted to XML. Signup for Our Newsletter and Receive New Articles Through Email.

Name:

Email:

Note : We never rent, trade, or sell our email lists to anyone. We assure that your privacy is respected and protected.

 

 

Add to My Yahoo!

Visit XML Training Material Guide Homepage

 

 

Copyright - © 2004 - 2017 - All Rights Reserved.