wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Record Byte Lengths vs Record String Lengths 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 "Record Byte Lengths vs Record String Lengths" Watch "Record Byte Lengths vs Record String Lengths" New topic
Author

Record Byte Lengths vs Record String Lengths

Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Hey Guys,

I've noticed the following behaviour when writing out to my 8 byte rate (holds a price and currency symbol) field:

when I set the String value to be $49.99, everything is as expected.

when I set the String value to be E49.99 (where the E is actually the euro symbol - it doesnt show up on this forum when typed), the fields following the rate field overflow into their subsequent fields.

I guess that the problem is that the Euro currency symbol uses more bytes than the $ symbol. So this leads me to believe that I need to check the amount of bytes a String is using before I persist it to the database. I did not see any mention of this in DennysDVDs or in the Monkhouse book. So is there something else I could consider?

Perhaps I need to explicitly set the encoding of the data before I persist it to the database? Again, I have not heard mention of this before either on here or in the book. I see where the encoding is set to UTF-8 when reading from the database in DennysDvds, but not when writing to the db.

Can someone please point me in the right direction?

Thanks,

g


OCPJP 6, OCMJD
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4913
    
  10

Weird! My instructions clearly state:
The character encoding is 8 bit US ASCII.


Because US ASCII is a 7-bit character ecnoding, I decided to use ISO-8859-1 (which I also documented in my choices.txt)


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Hi Roel,

Yet again you've qucikly cleared things up My instructions clearly state the same as yours regarding encoding.

I did not think that the encoding would fall under the remit of this assignment.

I have changed the encoding from UTF-8 to ISO-8859-1 and I no longer see the field overflow.

However, the euro symbol gets converted to ? (question mark symbol).

Does this mean that I should convert the text back to UTF-8 before presenting to the user?
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

ok, I understand now that I need to encode before persisting to the database and decode before presenting to user.

My question now becomes - which encoding can / should I use?

If anyone has a link to any literature explaining the pros and cons of each type I would be very grateful
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4913
    
  10

My file has only $ symbol. So I don't know why you are interested in showing/saving the Euro symbol. Furthermore the rate field can't be changed, nor can you create new records.

Like I said before: I used ISO-8859-1. According to instructions you must use a 8-bit character encoding and if you really want to use the Euro symbol you can maybe opt for this character encoding.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Record Byte Lengths vs Record String Lengths
 
Similar Threads
Database read problem
NX: Bodgitt and Scarper: what to do with the db-2*3.db file? write a parser? and...
SCJD assignment changed!
Database file reader
The file format is wrong.