Reputation: 635
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>");
}
Upvotes: 1
Views: 994
Reputation: 3095
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.
Upvotes: 1