• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Record Byte Lengths vs Record String Lengths

 
Ranch Hand
Posts: 176
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Glen Iris
Ranch Hand
Posts: 176
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 176
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic