Forums Register Login

DB Field Length Validation Question

+Pie Number of slices to send: Send
Hi

I have just started my SCJD Coursework, I have been assigned a variety of Bodgitt and Scarper. :-)

In the Coursework Database Schema specification it states the length of each field in bytes, for example from B&S coursework:

Field Descriptive Name | Database Field Name | Field length
-----------------------|---------------------|--------------
Subcontractor Name | name | 32
City | location | 64

So in a setter for the Subcontractor name above would the length check be

OPTION 1:

if(name.length > 64 || name.length = 0)
{
throw IllegalArgumentException("error message etc")
}

or

OPTION 2:

if(name.getBytes("US-ASCII").length > 64 || name.length = 0)
{
throw IllegalArgumentException("error message etc")
}

I am quite certain that OPTION2 is the correct check however I thought I would see what the wise SCJD forum thinks?

Thanks if advance.

Simon
+Pie Number of slices to send: Send
Hi,

I'll use "ISO-8859-1".

Check this thread: Data File Format - US ASCII

Just document your decision.

bye,
Alex
[ November 23, 2007: Message edited by: Alex Belisle Turcot ]
+Pie Number of slices to send: Send
hi

why you hard coded the lenght size , 64 , i think you are to save these value when you read it from the sechema section in the file , also i do what you do and throw the Illegal .... when any field size greater than expected .


OPTION 2:

if(name.getBytes("US-ASCII").length > 64 || name.length = 0)
{
throw IllegalArgumentException("error message etc")
}



m_darim.
SCJP, SCJD (in progress ... )
+Pie Number of slices to send: Send
Hi,

Just for the record, you should not use the charset JUST when checking the length.. anytime you convert bytes to String... (when reading and writing)

If you use the default one, then its fine, you use the default one all the time. Otherwise, you use different charset when reading/writing and checking the size..

bye,
Alex
Bring out your dead! Or a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 708 times.
Similar Threads
recNo in Bodgitt and Scarper
Bodgitt and Scarper questions
Some questions on "Bodgitt and Scarper"
Bodgitt and Scarper, LLC. assignment - Database field name "size"
NX: Bodgitt and Scarper: what to do with the db-2*3.db file? write a parser? and...
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:03:29.