1

I am querying the database. And trying to conert the data from a particular table and display that as an xml. I tried the following code, but still the xml is empty. I am still checking what is the problem. In mean time I am posting here. Can anyone please check and tell what is the problem?

response.setContentType("text/xml"); 

private void writeToXML(PrintWriter pw, ResultSet rs, Map<String, String> m)
      throws Exception {
    pw.print("<data>\n");
    rs.beforeFirst();
    while (rs.next()) {
      pw.print("\t<row>\n");
      ResultSetMetaData metaData = rs.getMetaData();
      int cols = rs.getMetaData().getColumnCount();

      for (int i = 1; i <= cols; i++) {
        String name = metaData.getColumnName(i);
        String mappedValue = m.get(rs.getString(i));
        String value = mappedValue != null ? mappedValue : rs
            .getString(i);
        pw.print("\t\t<name>" + name + "</name><value>" + value
            + "</value>\n");
      }
      pw.print("\t</row>\n");

    }
    pw.print("</data>");

  } 

2 Answers 2

1

did you flush (and later, closed) the printWriter ?

pw.flush(); 
Sign up to request clarification or add additional context in comments.

Comments

1

You might be getting some exception. PrintWriter swallows exceptions.

Use System.out and see if the program is executing and if no then what exception you are getting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.