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 3238162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:49:19+00:00 2026-05-17T17:49:19+00:00

Interested how to do it programmatically, not export table data once (there are tools

  • 0

Interested how to do it programmatically, not export table data once (there are tools for sure).

easiest way to transform mysql table “as is” into xml document ?

table contains say 2 rows:
id name
1 “John Travolta”
2 “Mary Lynch”

ideally we’d need a class that’s gonna eat login/passw/host of a database and

  GoodClass goodClass = new GoodClass(login, passw, host);
  String xml = goodClass.getTableData(nameOfTable);

 // xml : <table><row><num>1</num><id>1</id><name>John Travolta</name></row><row><num>2</num><id>2</id><name>Mary Lynch</name></row></table>
  • 1 1 Answer
  • 2 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-05-17T17:49:19+00:00Added an answer on May 17, 2026 at 5:49 pm

    If you wanted to go overboard, you could use hibernate to get your database results as Java objects and then use JAXB or JiBX to marshal the objects to XML. But the easiest way is to connect to your database, execute a query, loop over the resultset and build the XML. Example code is shown below:

    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) {
                   }
           }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to programmatically trace the execution of all python functions/methods? I
Is there any way to get the actual data that will be sent when
Is there a way to programmatically check if a single C source file is
Is there a way to programmatically list all geo-tagged Wikipedia entries within a radius
Is there a reliable, quick, deterministic way (i.e. not a benchmark) to check whether
Is there a way to programmatically change the screen resolution or enable/disable multiple monitors
I interested to work with data types and file formats. For example I want
I am interested in theoretical Big-O analysis of the following MySQL query: SELECT id,
I am interested in CD identification. My Question: Is there a serial number that
This question is limited in scope to HotSpot generations . Is there any way

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.