Wednesday, April 28, 2010

Result set to XML data conversion

public static Document (ResultSet rs)
throws ParserConfigurationException, SQLException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
String ApplicationConfigurationData[] = new String[4];
ApplicationConfigurationData[1] = "say";
ApplicationConfigurationData[2] = "pulkam";

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

while (rs.next()) {
Element row = doc.createElement("Row");
results.appendChild(row);

for (int i = 1; i <= 2; i++) {
// String columnName = rsmd.getColumnName(i);
Object value = rs.getObject(i);

Element node = doc
.createElement(ApplicationConfigurationData[i]);
node.appendChild(doc.createTextNode(value.toString()));
row.appendChild(node);
}
}
return doc;
}

No comments:

Post a Comment