Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet problem

 
Jess Ishasder
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic