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.

Dreamtech Press Book Release: Dreamtech Strengthens Its Presence with "Java EE 5 Black Book" (PR.com)
Dreamtech Press, a leading publisher forays into Java EE 5 Education, by introducing new "Java Server Programming Java EE 5 (J2EE 1.5) Black Book"- a book for Java EE 5 education. The book is launched with a combined vision to increase the productivity of Java Professionals by implementing effective learning theories. Book Details: ISBN – 978-81-7722-835-9; Price – 599/- w/CD. [PR.com - July 18, ...

Monitoring network performance with GNetWatch (NewsForge)
GNetWatch is a network monitoring and performance testing tool that lets you can see the status of hosts on your network, send ping requests of varying size and quality of service to hosts, and investigate SNMP information. GNetWatch includes support for using Wireshark and nmap to snoop packets and investigate hosts on the network.

The SocialDNS Project… and Why DNS is Not the Phone Book of the Internet (CircleID)
In this article I will explain the motivations behind the SocialDNS Project. I will justify why the DNS system is NOT the phone book of the Internet. More concretely, DNS is not a public directory nor enables search mechanisms over meta-information related to domains. In this line, I will present the advantages of SocialDNS, a naming and directory system that aims to become the phone book of ...



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.

_______________________________________

Recommended XML Books

cover
cover
cover
cover
cover
cover





 

 

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!


New XML Books Titles - Best Seller's @ Amazon.com

Visit XML Training Material Guide Homepage

Technology helps engage students - how do classroom instruction and social dynamics change when the classroom is completely dependant on modern technology?

Dallas Web Design- local Dallas web design firm offers site design and backend system development