• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

start position of data in db file in Bodgit and Scraper

 
pramod karnani
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all ,

I know start position in db file is 70 in Bodgit and scraper project
but i do not want to hard code 70 ,

Can any body tell me how to get start position of data in db file instead of hard coding 70??


please reply
bye
pramod
 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just create constant like

public static final int STARTING_POINT = 70;

Or something like that.

Jeffry Kristianto Yanuar (Java Instructor) SCJP 5.0, SCJA, SCJD (UrlyBird 1.3.2)
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

read in your specs about the location in the file where this value reside so dynamically read it and consider the value as start of your data section.

regards.
 
Carlos Lacerda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my project in constructor of Data class i sum values of header and store in a static var FIRST_RECORD_POSITION.
I use this var to navigate in file.
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have determined the position of your file pointer for data section while reading your database. If you have already determined, store the value in a variable and use it. There is no need to hard code. Because I am doing in this way ;)

sat
 
Carlos Lacerda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KARNANI,

Follow is my solution:



I have created a Schema class to store data information of fields of file.

I hope i have helped.
 
pramod karnani
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks carols , appreciate you .
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Carlos Lacerda,

i have a query regarding your solution.You have created a separate class named Schema to implement the Schema description section of the Data file format.Since the field length is already known and fixed by the given instructions("instructions.html) why should we read the records by creating a class.Why not we keep it as static int fields like this



Is creating a new class suggested or keeping it as a static constants fields suggested.However the same record field and length exists.
Also does sun use some other datafile will these things change.Then i know the hardcoding that i used above will not work.Which one is suggested?

Please do clarify
 
Naveen Hegde
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sree,
I agree with Carlos. It is better approach to dynamically initialise the schema reading from the db file.
I use the info available in instructions.html only to decide how many bytes to read to get following data:
private static Integer magicCookie;
private static Short numOfFields;
private static String[] fieldNamesArr;
private static Byte[] fieldSizeArr;

This makes data access class more generic and hence can work with any change in Column Names/Sizes or any other files of same format!
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Naveen for your reply.I think this really a good idea in the point of dynamism but i doubt whether a class is needed or simply a method would be sufficient.Is this correct?
 
Naveen Hegde
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Method like 'initSchema' should suffice. I think creating a seperate class may be too much of granularity as far as scope of the assignment is concerend. So i manage with a block of code in DataAccess class itself.
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks naveen hegde for your reply
 
Carlos Lacerda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sree visu wrote:Dear Carlos Lacerda,

i have a query regarding your solution.You have created a separate class named Schema to implement the Schema description section of the Data file format.Since the field length is already known and fixed by the given instructions("instructions.html) why should we read the records by creating a class.Why not we keep it as static int fields like this



Is creating a new class suggested or keeping it as a static constants fields suggested.However the same record field and length exists.
Also does sun use some other datafile will these things change.Then i know the hardcoding that i used above will not work.Which one is suggested?

Please do clarify


Hi Sree,
Sorry for delay,

As Naveen said, this approach is for dinamic use, and for flexibility of changes.
For me its is more simple and easy for use where reads or writes in file is necessary.
eg:


Using the Schema class with information fields loaded i use



Like this above, this is more simple for reads and writes to a file in my vision, but your solution is good constants and use of schema class both are good solutions, you can analyse what cause more work and what is more simple for other programmers use after you coded your solution.
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Carlos Lacerda for your reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic