• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is going wrong plz help

 
shobhit garg
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi what is going wrong with this peice of code
it simply searches the record store for a record that has contains a particular name and then returns its record id...
but i'm always getting the same record id returned back i donowhy


public int getIDByName(String name){
System.out.println("************"+name);
int ID=0, found =0;
try{
recEnum=rs.enumerateRecords(null,null,false);
while(recEnum.hasNextElement())
{if(name.equals(getName(new String(recEnum.nextRecord()))));
{recEnum.reset();
ID = recEnum.nextRecordId();
break;
}

}
}catch( Exception e)
{System.out.println("enumeration error");
}
recEnum.destroy();
System.out.println("**************"+ID);
return ID;
}

plz help if u can
thanxk
shobhit
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple of quick comments about your code.

First there is a CODE tag under the Add Reply button when posting here, that will keep your code formatting. Like tabulation and stuff that will make it much more readable for us.

Also you might want to read the Sun Java coding standards documentation. I find your placement of Curly braces to really go against the standard.

The curly braces, according to Sun's standards is



Standards are not necessarily saying that one way is correct or better than another, it is just a way to get everyone speaking the same language and be on the same page, without having to learn someone else's way of coding.

As far as your problem, How many records are in your record store, what is the value that you keep getting? Is it 0? or the last number? why are you calling reset() on the Enumeration?

Thanks

Mark
 
shobhit garg
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:
A couple of quick comments about your code.

First there is a CODE tag under the Add Reply button when posting here, that will keep your code formatting. Like tabulation and stuff that will make it much more readable for us.

Also you might want to read the Sun Java coding standards documentation. I find your placement of Curly braces to really go against the standard.

The curly braces, according to Sun's standards is




Standards are not necessarily saying that one way is correct or better than another, it is just a way to get everyone speaking the same language and be on the same page, without having to learn someone else's way of coding.

As far as your problem, How many records are in your record store, what is the value that you keep getting? Is it 0? or the last number? why are you calling reset() on the Enumeration?

Thanks

Mark


thanx for correcting me mark
i always keep getting the first record
according to the jkava doc reset restores the enumeration to state before
calling nextRecord
the problem is that once the desired name has been matched ie
if(name.equals(getName(new String(recEnum.nextRecord()))))
is true record enumeration already advances to the next record now how do i get the id of the record before this record

thanx again for correcting me
shobhit
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it appears from my tests that a call to nextRecord or nextRecordId will move the enumerator forward in both cases. This means that you can get one and not the other at the same time. Makes it kind of tricky there. Shame when you have a record you can't call a method on it to get its ID.

So maybe the solution to your problem is a re-design.

Why do you need the record number for a particular piece of data. Can you create a RecordFilter to make the Enumerator to only have the one record that you are looking for, and then just call nextRecordId() on that enumerator?

Mark
 
shobhit garg
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankx for the suugestion mark
i have redesigned the spec and now include the record id in the
record .i call getNextRecordId on record store instance before adding a new record and put it in the record
now my app is working
shobhit
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool, I am glad it is working. I actualy had had a sort of similar idea this morning while playing golf.

We could have done a call to nextRecordId, then using the id to call getRecord on the record store.

But sometimes when you get it working, sticking with what wokrs is the best way.

Good Luck with the rest of the program

Mark
 
shobhit garg
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks mark
shobhit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic