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); }