I would like to extract the specified field again after displaying all the fields in a record. The code is as follows: ============================ ....... while(rs.next()){ ps.println("<tr>"); for (int i=1; i<=nCols; i++) { ps.println( "<td width=20%>" + rs.getString( i ) + "</td>"); } } //Extract the field again String p = rs.getString(2);<---Why I can't get the value again???
ps.println("<td width=20%><font color = red>$" + subtotal + "</font></td>"); ....... ....... Thank you for your help!!
Jotty Tharakan
Greenhorn
Joined: Dec 14, 2001
Posts: 17
posted
0
Since while rs.next() lop is over the resultset is pointing to the end.that's why it is not giving any record. To use the result set again for retrieving the values use rs.beforeFirst() and then u can use while rs.next() again to retrieve the values. Rgds George
i was also facing the exact problem with my project.i was also confused that why can't we use the getXXX() method on a cell more than once. I don't know whther or not my explanation is right but it worked for me and i am sure it will work for u also. what i thought was, that , that u can't move to the fields previous to the column u have started fetching the data from a (particular) row. Suppose u have 5 columns in the table and for a particular row u first executed the getXXX() method on column 3 than after that getXXX() method u can't move on to previous column nor u can again fetch the same column(3) again untill u move the cursor to any other row. SOLUTION..... what i did, i took the value of the cell that i need to access again-2 in a variable and then used that variable. JDBC gurus pls correct me if i am wrong with my reasoning part.