Win a copy of Rust Web Development this week in the Other Languages forum!

Paul O'Leary

Greenhorn
+ Follow
since Jun 19, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Paul O'Leary

Thanks Liviu, that resolved my problem with the file path using a Properties object and FileInputStream as the parameter.
Hi,

Does anybody know why the File separators on Windows are removed from the ResourceBundle.getString() invocation as follows?

System.out.println(resourceBundle.getString("dbfile"));
C:eclipseworkspacescjddb-2x3.db

Despite the fact that I use PrintWriter successfully to write the key=value pair as dbfile=C:\eclipse\workspace\scjd\db-2x3.db to the suncertify.properties file.

Thanks in advance,

Paul.

Originally posted by Mary John:
I am still confused as to how the header length is calculated correctly since the Customer ID is being written to the next row's name column in the JTable instead of the owner column. I am writing the Customer ID to the owner column as follows

Why would you want to write customer id alone? Dont you have an update method which sends a data array as argument and that needs every column to get updated?

I have the following B&S update method
public void updateRecord(long recNo, String[] data, long lockCookie)
throws RecordNotFoundException, SecurityException

here i make a string of size "recordLength" and then write the entire string starting at the record's first byte position

in your business method book(), you can choose to provide new value for owner and format your data array there.
I dont know if you thought already about it and your question is something else?



Thanks alot for clearing that up, I had assumed the updateRecord() was for booking the subcontractor only. I have finally been able to calculate the offset correctly.
I am still confused as to how the header length is calculated correctly since the Customer ID is being written to the next row's name column in the JTable instead of the owner column. I am writing the Customer ID to the owner column as follows:

<code>
int lengthRecord = 32 + 64 + 64 + 6 + 8 + 8;
long offset = 0;
offset = headerLength + recNo * (lengthRecord + 1);
//skip the delete flag with an additional byte
offset = offset + 1;
StringBuilder out = new StringBuilder(8);
out.append(data[5].trim()); //Customer id
try{
raf.seek(offset);
raf.write(out.toString().getBytes());
raf.close();
} catch(IOException ex){}
</code>

I am currently calculating the header length by raf.getFilePointer() after reading the Column headings.
I understand the header length is calculated by the size of the file from the beginning of the file to where the records start.
Can anyone comment on how to determine the header length correctly?

Originally posted by Mary John:
it should be determined as per the schema. what you might get in the data array could be strings of length lesser than that specified in schema.

eg if name length is 32 chars, then in the data[0], you might get something like "Bunarotti".

I didnt understand you second question about header lenght determination...?



Thanks Mary for your reply, my second question is basically about how the header offset is calculated ie. is it the number of bytes that the file pointer offset is at when it has read the last column heading for the 'owner' column?

Also should the contents of the data[] overwrite the existing record fields when the Customer id is written to the data file?
[ April 02, 2008: Message edited by: Paul O'Leary ]
In order to determine the offset to write the owner id value, is the length of a record determined by the length of elements in the data array or as per the database schema specified lengths?

Also is the headerLength determined by the filePointer position after reading the column owner heading?


Thanks,
Paul.
Having tried searching this forum for ideas which I must say is an excellent resource for other problems I have encountered so far, I am still unfortunately stuck trying to figure out how to parse the database file correctly to String arrays in order to display within a JTable in my GUI ie. how do I group the appropriate columns with their corresponding values?

I understand that the recommended way is to use a RandomAccessFile class to be used in conjunction with the DBAccess interface implementation so to enable any record to be accessed for searching, but initially all I want to be able to do is display all the records in the JTable.

Any hints, tips or examples would be most appreciated.