Sample code for how to convert XML elements into JDBC Resultset ?

Can any one give a sample code for how to upload xml data into MSAccess table ? I have the code for how to convert MSAccess table data to xml. I need a sample code for vice versa.
ramnramAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You just need to parse the xml and form insert statements. This would be very specific to the column names involved. Please give the ones in question.
0
ramnramAuthor Commented:
hey i am sorry for posting two mistake i want u people to answer any one only. u people pls give me a idea to delete this question. i cant giv 125 pts for the same question
0
ramnramAuthor Commented:
hey i am sorry for posting two questions of same type by mistake i want u people to answer any one only. u people pls give me a idea to delete this question. i cant giv 125 pts for the same question
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

sriven10Commented:
try this code. u wil certainly get an idea.


import java.sql.*;
import java.io.*;
import java.util.*;
import java.lang.*;

import java.io.StringReader;
import java.io.StringWriter;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.FactoryConfigurationError;

import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

//      Main class JavaXML

class  JavaXML
{
      static Connection connection = null;
      Statement statement = null;
      ResultSet resultset = null;
      int rowCount = 1;

// Static method call for the initial actions to be done

      static
      {
            try
            {
                  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                  connection = DriverManager.getConnection("jdbc:odbc:Test","","");
            }
            catch(Exception e)
            {
                  e.printStackTrace();
            }
      }

//      Finalize method for the final action

      public void finalize()
      {
            try
            {
                  connection.close();
            }
            catch(SQLException e)
            {
                  e.printStackTrace();
            }
      }

//      Method for getting the database list using Document object

      public Document getCustomerList()
      {
            Document document = null;
            try
            {
                  statement = connection.createStatement();
                  resultset = statement.executeQuery("select * from temp");
                  document = toDocument(resultset);
                  resultset.close();
                  statement.close();
            }
            catch(Exception e)
            {
                  e.printStackTrace();
            }
            return document;
      }

//      toDocument method for creating XML content

      public Document toDocument(ResultSet resultset) throws ParserConfigurationException,SQLException
      {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document document = builder.newDocument();

            ResultSetMetaData rsmd = resultset.getMetaData();
            int colCount = rsmd.getColumnCount();

            Element results = document.createElement("Results");
            document.appendChild(results);

            while(resultset.next())
            {
                  Element rows = document.createElement("Rows");
                  results.appendChild(rows);

                  for(int i = 1;i <= colCount;i++)
                  {
                        String columnName = rsmd.getColumnName(i);
                        Object value = resultset.getObject(i);

                        Element node = document.createElement(columnName);
                        node.appendChild(document.createTextNode(value.toString()));
                        rows.appendChild(node);
                  }
            }
            return document;
      }

//       Public method

      public static void main(String[] args) throws Exception
      {
            JavaXML jxml = new JavaXML();
            Document document = jxml.getCustomerList();
            try
            {
                  Source source = new DOMSource(document);
                  File file = new File("xmlfile.xml");
                  Result result = new StreamResult(file);
                  Transformer xformer = TransformerFactory.newInstance().newTransformer();
                  xformer.transform(source, result);
            }
            catch(TransformerConfigurationException e)
            {
                  e.printStackTrace();
            }

            catch(TransformerException e)
            {
                  e.printStackTrace();
            }
      }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ramnramAuthor Commented:
i am going to do onething
i am going to change the question

its relatively simple


Can any one give a sample code for how to convert a DB table to XML?

pls giv ur answers immediatly. since there is a answer already posted above. i wil wait for another 2 days.

0
ramnramAuthor Commented:
Dear CEHJ,

pls do me a favour. pls send ur above comment to ques no.

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21182437.html

i wil consider ur comment in tat question. sorry for the inconvienience.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.