Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8204369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:52:45+00:00 2026-06-07T07:52:45+00:00

There is a code that exports the data from the database in xml. public

  • 0

There is a code that exports the data from the database in xml.

    public class DataExtractor{

   private final String login, passwd, host;

   public DataExtractor(String login, String passwd, String host){
       this.login = login;
       this.passwd = passwd;
       this.host = host;
   }

   public String getTableData(String tableName) throws SQLException, ClassNotFoundException {
       Connection con = null;
       Statement st = null;
       ResultSet rs = null;
       try {
           Class.forName("com.mysql.jdbc.Driver");
           con = DriverManager.getConnection("jdbc:mysql:///" + host, login, passwd);

           st = con.createStatement();
           rs = st.executeQuery("select * from " + tableName);

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

           StringBuilder b = new StringBuilder("<table>\n");

           int num = 1;
           while (rs.next()) {
               b.append("<row>");
               b.append("<num>").append(num++).append("</num>");
               for (int i = 1; i <= colCount; i++) {
                   String columnName = rsmd.getColumnName(i);
                   b.append('<').append(columnName).append('>');
                   b.append(rs.getObject(i));
                   b.append("</").append(columnName).append('>');
               }
               b.append("</row>\n");
           }
           b.append("</table>");
           return b.toString();
       } catch (SQLException e) {
           throw e;
       } catch (ClassNotFoundException e) {
           throw e;
       } finally {
           if (rs != null)
               try {
                   rs.close();
               } catch (SQLException e) {
               }
           if (st != null)
               try {
                   st.close();
               } catch (SQLException e) {
               }
           if (con != null)
               try {
                   con.close();
               } catch (SQLException e) {
               }
       }
   }
}

But this class of exports only the data from a given table, how to make sure that the data exported from the entire database (ie, all tables), and not from a particular table. That is, should get the output XML file types:

  <database>
      <table1>
             <id> </ id>
             <Name> </ Name>
                           ...
       </ table1>

        <table2>
               ...
       </ table2>


</ database>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:52:46+00:00Added an answer on June 7, 2026 at 7:52 am

    Use:

    show tables
    

    then loop over the tables and call your method getTableData()

    You might want to consider getting the columns names as well:
    SHOW columns FROM table

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is some code that I'm trying to convert from IList to IEnumerable :
I have a website that currently takes data from a mysql database and using
For testing code I'm copying data from a live database to a test database
I am generating a CSV file containing data from a MYSQL database. There are
We are using an extractor application that will export data from the database to
I have a program that is generating Xml Files from data out of a
In a .f file there is code that does this: real Bob, avar ...
I'm currently reading Rails 3 In Action. There is code that I was wondering
There is some code that I am using written by someone else that I
There's a code that reads a file and makes some calculating operations with its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.