Using java and extracting XML data through JDBCExtracting 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"); 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.
|
|
|||
|
||||
“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”
Copyright - © 2004 - 2019 - All Rights Reserved.