Skip to Content
0
Aug 28, 2007 at 06:46 AM

resultSet.previous() not working

137 Views

Hi

I have a requirement where based on a condition i need to traverse to the previous record in the database. But i am not able to use it. It throws following exception"Invalid operation for forward only resultset : previous".

The code that i have is:

while(resultSet.next())
	{
		
		String abc= resultSet.getString(8);
		
		while(resultSet.getString(8).equals(abc))
		{
		IBS ibsAcctB= new IBS();
		ibsAcctB.setIbsAcct(resultSet.getString(9));
		ibsAcctResult.add(ibsAcctB);
		resultSet.next();	
		count++;
		}
		AccountBean AcctBean = new AccountBean();
		AcctBean.setibsAccounts(ibsAcctResult);
		AcctBean.setAcct(abc);		
		AccountResult.add(sapAcctB);
		resultSet.previous();

		this.setAccountResult(AccountResult);
		this.setUserId(resultSet.getString(1));
		this.setUserName(resultSet.getString(2));
		this.setUserCountry(resultSet.getString(3));
		this.setUserCompany(resultSet.getString(4));
		this.setUserType(resultSet.getString(5));
		this.setLanguage(resultSet.getString(6));

	}

In the above piece of code, when the condition is not satisfied, cursor moves out of the inner loop, and then the next iteration of the outer loop starts. but here, when the user once moves out of the inner loop, resultSet.next() has incremented the counter. At that point, the outer counter is again incremented. Which results in one record getting skipped. So i wanted to decrement the counter by 1 in case the inner condition is not satisfied. But i am not able to.

If anyone has worked on it, please let me know..

Thanks & regards,

Anupreet