File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes ResultSet problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "ResultSet problem" Watch "ResultSet problem" New topic

ResultSet problem

Jess Ishasder

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:
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

Joined: Dec 14, 2001
Posts: 17
Since while 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 again to retrieve the values.
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)

[ 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.
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:
subject: ResultSet problem
It's not a secret anymore!