Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

last row in resultset

 
sahidul karim
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a set of rows .i am selecting a query .its giving 5 rows.i want to take only last one.How can i take?
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to move to the last row in a resultset, you can use "last()" method available in the Resultset interface.

Just have a look at the javadocs.
[ September 28, 2006: Message edited by: Srinivasa Raghavan ]
 
sahidul karim
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i want to retieve last row value .if i write in while loop like resulset.next() its going in infinte loop.so how can i resolve this problem
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure whether I understood your problem. Why cant you use the below code directly. Why you need next() here ?
resultset.last()
 
sahidul karim
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya i have used .but its goinin infinte loop.ok i m giving the code.

String sQuery="select salary_adv,salary_adv_paid,salary_adv_bal from emp_advance where emp_id= '"+Emp_Id+"' order by adv_date";
ps=connection.prepareStatement(sQuery);
resultset=ps.executeQuery();

while(resultset.last())
{
String saladvt=Float.toString(resultset.getFloat("salary_adv"));
String saladvp=Float.toString(resultset.getFloat("salary_adv_paid"));
String saladvb=Float.toString(resultset.getFloat("salary_adv_bal"));

}

its going infinte loop.but i want to store value of last row in those string .how can i achieve?
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes definetly you will go into an infinite loop, since the cursor in not going forward and it stays in the last row. Check the below code it should work if the result set returns atleast one row.


[ September 28, 2006: Message edited by: Srinivasa Raghavan ]
 
sahidul karim
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnaks i got the answer.actually i was using a while loop.thats why it ws iterating infintely.i chaged it to if loop.now its working fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic