String[] columnNames = new String[columnCount]; Element names = document.createElement("names"); for (int i = 0; i 〈 columnCount; i++){ /* the first column is 1, the second is 2, ... */ columnNames[i] = rsmd.getColumnName(i + 1); Element nextNameNode = document.createElement("name"); Text nextName = document.createTextNode(columnNames[i]); nextNameNode.appendChild(nextName); names.appendChild(nextNameNode); }
/* Move the cursor through the data one row at a time. */ while(resultSet.next()){ /* Create an Element node for each row of data. */ Element nextRow = document.createElement("row"); if (debug) System.out.PRintln("new row"); for (int i = 0; i 〈 columnCount; i++){ /* Create an Element node for each column value. */ Element nextNode = document.createElement(columnNames[i]); /* the first column is 1, the second is 2, ... */ /* getString() will retrieve any of the basic SQL types*/ Text text = document.createTextNode(resultSet.getString(i + 1)); nextNode.appendChild(text); nextRow.appendChild(nextNode); } root.appendChild(nextRow); }