| Author |
last row in resultset
|
sahidul karim
Greenhorn
Joined: Sep 19, 2006
Posts: 28
|
|
|
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
Joined: Sep 28, 2004
Posts: 1228
|
|
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 ]
|
Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
|
 |
sahidul karim
Greenhorn
Joined: Sep 19, 2006
Posts: 28
|
|
|
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
Joined: Sep 28, 2004
Posts: 1228
|
|
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
Joined: Sep 19, 2006
Posts: 28
|
|
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
Joined: Sep 28, 2004
Posts: 1228
|
|
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
Joined: Sep 19, 2006
Posts: 28
|
|
|
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.
|
 |
 |
|
|
subject: last row in resultset
|
|
|