Page 1 of 1
About Question enthuware.ocpjp.v7.2.1261 :
Posted: Fri Sep 20, 2013 3:24 am
by The_Nick
Hi,
I read precedently that in order to proper match this joins, it's necessary to use setKeyColumns(arrayKey);.
So far I have never seen a use of this method.. do you know when it helps?
I thought that at least the 2 CachedRowSet created in this question should have declared "setKeyColumns(new int[]{1});" but apparently there is no need.
Again, when is it indeed mandatory the method setKeyColumns?
Thanks in advance.
The_Nick.
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Fri Sep 20, 2013 5:56 am
by admin
To do a join, you need match columns (not key columns). If you specify join columns while adding rowsets to JoinRowSet, so Key columns on individual rowset are not required. See the parameters of JoinRowSet.addRowSet.
The API description of this method explains the details:
http://docs.oracle.com/javase/7/docs/ap ... olumns(int[])
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Fri Sep 20, 2013 6:42 am
by The_Nick
I have gone through those API, it does not say when it's indispensable to be used. However it's mentioned in CachedRowSet java tutorial description, without explaning the case in particular. All the operation I ever made with any rowset, I have never come across the need to use setKeyColumn, I am wondering if it's for future purposes.
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Fri Sep 20, 2013 6:54 am
by admin
The API description is quite clear on its purpose, "Sets this CachedRowSet object's keyCols field with the given array of column numbers, which forms a key for uniquely identifying a row in this CachedRowSet object.
If a CachedRowSet object becomes part of a JoinRowSet object, the keys defined by this method and the resulting constraints are maintained if the columns designated as key columns also become match columns."
Not sure what is the confusion. If you want to uniquely identify a row in a CRS, use setKeyColumns. Otherwise, don't.
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Sat Oct 12, 2013 8:48 pm
by icepeanuts
About the code shown in the explanation:
JoinRowSet jrs2 = rsf.createJoinRowSet();
jrs.setMatchColumn("SUBJECT"); //First change the match column of first jrs to SUBJECT.
jrs2.addRowSet(jrs);
jrs2.addRowSet(teacherRS, "SUBJECT");
Can I change it to the following?
JoinRowSet jrs2 = rsf.createJoinRowSet();
jrs2.addRowSet(jrs);
jrs2.setMatchColumn("SUBJECT");
//jrs2.addRowSet(jrs);
jrs2.addRowSet(teacherRS, "SUBJECT");
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Sun Oct 13, 2013 8:06 am
by admin
No, you can't call jsr2.addRowSet(jrs); because it will throw an exception if the match column is not set before this method is called. Please go through the API description of JoinRowSet to see how it works. They have explained it really well at
http://docs.oracle.com/javase/7/docs/ap ... owSet.html
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Sat Oct 26, 2013 7:18 pm
by icepeanuts
thank u
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Mon Mar 09, 2015 8:23 am
by ArnobDe
Code: Select all
JoinRowSet jrs2 = rsf.createJoinRowSet();
jrs.setMatchColumn("SUBJECT"); //First change the match column of first jrs to SUBJECT.
jrs2.addRowSet(jrs);
jrs2.addRowSet(teacherRS, "SUBJECT"); //Now match jrs's SUBJECT with teacherRS's SUBJECT.
Will it work? if we simply add
to the code in the question right before
Code: Select all
jrs.addRowSet(teacherRS, "SUBJECT");
why do we need to construct a different JoinRowSet i.e jrs2?
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Mon Mar 09, 2015 11:30 am
by admin
Did you read the explanation? It explains exactly what you are asking.
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Tue Apr 28, 2015 8:35 am
by Alina_Lapina
Is it right, that every time I need to change a matching column, I need to create a new instance of JoinRowSet?
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Tue Apr 28, 2015 8:41 am
by Alina_Lapina
Can I change
jrs.setMatchColumn("SUBJECT"); jrs2.addRowSet(jrs);
to
jrs2.addRowSet(jrs, "SUBJECT");
?
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Tue Apr 28, 2015 8:58 am
by admin
Alina_Lapina wrote:Is it right, that every time I need to change a matching column, I need to create a new instance of JoinRowSet?
Yes.
Re: About Question enthuware.ocpjp.v7.2.1261 :
Posted: Tue Apr 28, 2015 8:59 am
by admin
Alina_Lapina wrote:Can I change
jrs.setMatchColumn("SUBJECT"); jrs2.addRowSet(jrs);
to
jrs2.addRowSet(jrs, "SUBJECT");
?
Yes