aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes getRecordCount Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "getRecordCount" Watch "getRecordCount" New topic
Author

getRecordCount

David Dong
Ranch Hand

Joined: Aug 15, 2004
Posts: 58
I wrote the below code. It compiled and when I run it, my main.getRecordCount() is not updated and it should because the main.create() creates a new row to the database.
Here is my code:

String[] a={VALID_RECORD+"","Dogs with To ","Whoville","aa",null,null,"bb"};
int n=main.create(a);
System.out.println("created row "+n);

for(int r=1;r<main.getRecordCount();r++){
String[] str=main.read(r);
StringBuffer rv = new StringBuffer("recordNumber = " + r +"\n");
for (int i = 0; i < main.fieldInfo.length; i++) {
rv.append( main.fieldInfo[i].getName()+" "+" = " + str[i]+"\n");
}
System.out.println(rv.toString());
}

Please help, anyhelp will be appreciated,
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
do you create to and read from the same target? Maybe you create in a cache without flushing into disk but read from physical disk. Don't know how you implement your create and read.


--------<br />Andy Zhu<br />scjp 1.4<br />scjd 1.4<br />SAS Certified Programmer 9.0
David Dong
Ranch Hand

Joined: Aug 15, 2004
Posts: 58
// Creates a new record in the database (possibly reusing a
// deleted entry). Inserts the given data, and returns the record
// number of the new record.
public int create(String [] data) throws DuplicateKeyException;

// Reads a record from the file. Returns an array where each
// element is a record value.
public String [] read(int recNo) throws RecordNotFoundException;

[Andrew: put the source code between [code] and [/code] UBB tags]

[ September 13, 2004: Message edited by: Andrew Monkhouse ]
[ September 13, 2004: Message edited by: David Dong ]
David Dong
Ranch Hand

Joined: Aug 15, 2004
Posts: 58
Please help everyone, by the way Thanks Andy !
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Hey, David:

first you may want to quote your code in so that it has original format. Now reading your code is somehow awkward.

I didn't read thru your code. But when you copy your data for name and location, you use index 1 and 2. As I understand, they should be indexed 0 and 1. (flag is in disk, and not a field in the data format specified that is why data[0] for name). This is from my instruction and interpretation. Read yours carefully and may solve the problem.
David Dong
Ranch Hand

Joined: Aug 15, 2004
Posts: 58
I was thinking to have flag as a separate part from the field but I think it is better to count flag as a field.
by the way Which assignment do you have?

are you able to solve the mystery of why my getRecordCount isn't updated, when it's run after create ?
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
I see nowhere you did update record count. your recordCount is a local variable. you have getRecordCount() which I don't know if you increment counter after getting one or you have somewhere to set record count, or you have an some sort of instance variable to keep the record for you.

Anyway, I didn't find in your code you try to update counter.
David Dong
Ranch Hand

Joined: Aug 15, 2004
Posts: 58
Sorry ,
I have the getRecordCount by reading the database.
I made a create a new row to the database, and it seems like it gets updated before getRecordCount being called.
But getRecordCount gets the old count instead of the oldCount + 1.

Do you understand better now?
David Dong
Ranch Hand

Joined: Aug 15, 2004
Posts: 58
Andy,
I solved it. It was the for loop. Thank you very much for your help..
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11422
    
  85

Hi David,

I have edited your post to put the code between [code] and [/code] UBB tags. Doing this ensures that indenting is preserved, which hopefully makes the code easier to read. I did not change your indenting though.

When you are writing your post, there are a number of buttons just below the edit pane, which will insert the tags for you, so you don't have to remember what they are.

If you would like to edit your original post so that you can see what I have done, you can click on the button that is just above your post.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
David Dong
Ranch Hand

Joined: Aug 15, 2004
Posts: 58
Ohh.. I didn't know. Thanks for letting me know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getRecordCount