Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes ResultSet problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet problem" Watch "ResultSet problem" New topic
Author

ResultSet problem

Jess Ishasder
Greenhorn

Joined: Feb 19, 2002
Posts: 21
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???

double subtotal = q * (Double.valueOf(p).doubleValue());

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
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
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

something doesn't seem right here. This is what you are doing (whether you know it or not)

Jamie
[ March 07, 2002: Message edited by: Jamie Robertson ]
rahul kumar
Ranch Hand

Joined: Feb 24, 2001
Posts: 75
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet problem