Page 1 of 1
About Question enthuware.ocpjp.v7.2.1200 :
Posted: Sat Sep 14, 2013 11:38 am
by The_Nick
Hi,
I see that the following line of code:
Is fundamental otherwise if I try to remove it I get a SQLException "invalid cursor".
Why would be that?
Furthermore instead of rs.isAfterLast() I could insert (!rw.getRow()==0) and I would have got the same result;
The_Nick
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Sat Sep 14, 2013 2:43 pm
by The_Nick
Forget about it, I got what it was.
It probably gets looped when loaded internally, that's why it's needed checking rs.isAfterLast in order to avoid failure.
The_Nick.
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Sat Sep 14, 2013 2:59 pm
by The_Nick
Wait a minute, actually I was wrong, the problem still persists:
Code: Select all
while(result.next())//result is a valid ResultSet
{
System.out.println(result.getInt(1));
}
The above code does not need the !isAfterLast control so why for the RowSet in evaluate(RowSet rw) it's needed?
Thanks a lot in advance!
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Sat Sep 14, 2013 6:46 pm
by admin
It is not really required if you catch the exception in the filter and return false.
The reason given code uses it is because in dumpRS(), the loop uses while(rs.next()). So after the last rows is printed, the filter is invoked with the pointer pointing to "one after the last row". So now you can either expect an exception and catch it or avoid the exception by checking for isAfterLast.
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Sun Sep 15, 2013 2:39 am
by The_Nick
admin wrote:It is not really required if you catch the exception in the filter and return false.
The reason given code uses it is because in dumpRS(), the loop uses while(rs.next()). So after the last rows is printed, the filter is invoked with the pointer pointing to "one after the last row". So now you can either expect an exception and catch it or avoid the exception by checking for isAfterLast.
HTH,
Paul.
Ok, however why in the following code there is no need of such a check?
Code: Select all
while(result.next())//result is a valid ResultSet
{
System.out.println(result.getInt(1));
}
Does not it go in afterLast for the last call of getInt(1)?
Thanks in advance.
The_Nick.
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Sun Sep 15, 2013 5:50 am
by admin
Sorry, not really sure why. I searched for more details in the documentation but couldn't find anything that could give any pointers.
-Paul.
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Wed Sep 25, 2013 9:28 am
by Student
Hi,
It says at
http://docs.oracle.com/javase/tutorial/ ... ate-object:
To set the criteria for which rows in a FilteredRowSet object will be visible, you define a class that implements the Predicate interface. An object created with this class is initialized with the following:
- The high end of the range within which values must fall
The low end of the range within which values must fall
...
Note that the range of values is inclusive, meaning that a value at the boundary is included in the range.
In the implementation of evaluate in the example, it doesn't do this:
Should that not be
? I am unclear: am I misunderstanding what Oracle are saying, or is what they say a guideline, and the code doesn't follow it? Or perhaps..none of the above

Thanks.
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Wed Sep 25, 2013 5:12 pm
by admin
The high/low end test can be implemented either using > or >= (or < or <=) . For example, if an acceptable end is say 3, you can do <=3 or <4 (assuming the data type is int). So there is no restriction on what you comparison code must look like.
In this case, the question has not mentioned any high/low end range. It shows a code and based on that code, you need to determine the result. Had the question mentioned that 4.0 is the low end starting point and then your point might have been valid.
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Fri Feb 07, 2014 7:13 am
by Ambiorix
Why would you go to the bother of creating a filter class when you could just include something like 'and GPA > 4.0' in the original select statement?
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Fri Feb 07, 2014 7:27 am
by admin
Ambiorix wrote:Why would you go to the bother of creating a filter class when you could just include something like 'and GPA > 4.0' in the original select statement?
To illustrate an approach, of course

Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Fri Feb 07, 2014 8:27 am
by Ambiorix
admin wrote:Ambiorix wrote:Why would you go to the bother of creating a filter class when you could just include something like 'and GPA > 4.0' in the original select statement?
To illustrate an approach, of course

I was thinking more generally. What's the point of the FilterRowSet? Is it not always easier just to get the select statement to pick the rows that meet the criteria you want?
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Fri Feb 07, 2014 8:34 am
by admin
You might want to apply a filter on an existing rowset. It is just a facility/feature. It might not be useful very often but it could be useful when the opportunity to fire query is not present or the way you want to filter is not possible to code in the query.
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Tue Aug 19, 2014 6:03 pm
by telston
Section 9 of the exam guide at docs.oracle.com/javase/tutorial/extra/certification/javase-7-programmer2.html#jdbc does not cover the section about FilteredRowSet. It covers only RowSet as a general interface and JdbcRowSet. Does the actual exam cover detailed use of CachedRowSet, WebRowSet, FilteredRowSet, and JoinRowSet?
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Tue Aug 19, 2014 7:39 pm
by admin
Yes, we have seen candidates getting question on these RowSets.
See this:
http://www.coderanch.com/t/657283/java- ... -Enthuware
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1200 :
Posted: Wed Dec 10, 2014 11:43 pm
by lunars
If there is anyone else who, like me, was at first confused about the purpose of there being three evaluate methods, read the javadoc again more carefully!
http://stackoverflow.com/questions/5619 ... ate-method
Basically, the non-RowSet overloads are called by FilteredRowSet when you insert rows, the RowSet one is for queries... Do I have that right?
So in the code from the present Enthuware question, the two non-RowSet overloads
would have affected the studentRS if we had moved to the insert row, updated its columns, and ran insertRow(). I suppose, since they returned false in ALL cases, any attempt to insert rows at all would have been blocked?
Thanks for any info in advance!