About Question enthuware.ocpjp.v7.2.1261 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

About Question enthuware.ocpjp.v7.2.1261 :

Post 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.

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post 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.
If you like our products and services, please help us by posting your review here.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post 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.

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post 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.
If you like our products and services, please help us by posting your review here.

icepeanuts
Posts: 53
Joined: Thu Nov 22, 2012 12:01 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post 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");

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post 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.
If you like our products and services, please help us by posting your review here.

icepeanuts
Posts: 53
Joined: Thu Nov 22, 2012 12:01 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post by icepeanuts »

thank u

ArnobDe
Posts: 8
Joined: Tue Jan 27, 2015 3:33 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post 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

Code: Select all

jrs.setMatchColumn("SUBJECT")
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?

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post by admin »

Did you read the explanation? It explains exactly what you are asking.
If you like our products and services, please help us by posting your review here.

Alina_Lapina
Posts: 15
Joined: Tue Jan 13, 2015 12:10 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post 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?

Alina_Lapina
Posts: 15
Joined: Tue Jan 13, 2015 12:10 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post by Alina_Lapina »

Can I change
jrs.setMatchColumn("SUBJECT"); jrs2.addRowSet(jrs);
to
jrs2.addRowSet(jrs, "SUBJECT");
?

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post 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.
If you like our products and services, please help us by posting your review here.

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1261 :

Post by admin »

Alina_Lapina wrote:Can I change
jrs.setMatchColumn("SUBJECT"); jrs2.addRowSet(jrs);
to
jrs2.addRowSet(jrs, "SUBJECT");
?
Yes
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests