The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

shivkpr (30) [Avatar] Offline
#1
Hi,
On page 101, you populate event type records into a hash map. the schedule bean then does a lookup to find the desc for the event type key. i'm finding the event types are being loaded but not being read back

i.e si.setEventType((String) eventTypes.get(
new Integer(si.getEventTypeKey())));

can you please help.

also not sre why when I used COLS[1] did not work but using an explicit

si.setStart(rs.getString("START_DT"))

it did.
where is the errdata for the book as well

i do hope there there are not too many bug fixes. is it better idea to download the source again with updated revisions

It is a good book though
nford (36) [Avatar] Offline
#2
Re: getevent types and hash map
Hello!

For both of your questions, I'm having a hard time reproducing them using the sample -- both issues work fine on mine. The COLS[] issue is especially interesting, as that array is defined in the same class (ScheduleDb) as the populate() method. I also verified that the Map's types are (Integer, String).

If you have more information or symptoms of these problems, please let me know because I'm quite curious as to what has caused them.

I'm working on an errata list now, and should have it up soon. I've uploaded a slightly newer version of the samples to Manning's site (which fixes some minor bugs in the build.xml files) but haven't had to update any of the code yet because no one has posted a reproducable (or even the same) problem yet. I'll update the samples as soon as I find a bug.

Thanks for your interest in the book, and I hope you continue to enjoy it.
shivkpr (30) [Avatar] Offline
#3
Re: getevent types and hash map
thanks for the update.as i said before I'm trying this on an oracle db

the driver i'm using is
oracle.jdbc.driver.OracleDriver;

my tables in the db are

desc event
Name Null? Type
----------------------------------------- -------- -------------------------
EVENT_KEY NOT NULL NUMBER(3smilie
START_DT VARCHAR2(10)
DURATION NUMBER(3smilie
DESCRIPTION VARCHAR2(50)
EVENT_TYPE NUMBER(3smilie

gdp@gdpt4.world> desc event_types
Name Null? Type
----------------------------------------- -------- -------------------------
EVENT_TYPE_KEY NOT NULL NUMBER(3smilie
EVENT_TEXT VARCHAR2(20)


The COLS issue is now but eventtypes HASH MAP even though its populated when it tries to


si.setEventType((String) eventTypes.get(
new Integer (si.getEventTypeKey())));

the mapping is lost.
is this due to oracle bigdecimal issue needs casting some other way ?
nford (36) [Avatar] Offline
#4
Re: getevent types and hash map
Yes, the "number" type in Oracle is what I suspect. Try running it in a debugger to see what actual type gets placed as the key in the hashMap. Alternatively, cast it to an integer when placing the records in the map to begin with -- the original version uses rs.getObject(...) to get the values for the keys. This could be changed to put a wrapped Integer in as key. For MySQL, getObject() return an Integer, and I suspect that Oracle does not.
shivkpr (30) [Avatar] Offline
#5
Re: getevent types and hash map
hi, In the Map it appears as big decimal

I've tried to Cast but not having as in

eventTypes.put(new Integer (rs.getInt("event_type_key")),
rs.getString("event_text"));

but does not like it.

How do you put ina wrapped integer in for the key
nford (36) [Avatar] Offline
#6
Re: getevent types and hash map
> How do you put ina wrapped integer in for the key

In ScheduleDb, on line 119, the getEventTypes() method lazily loads the eventTypes map, using this code:

eventTypes.put(rs.getObject("event_type_key"),
rs.getString("event_text"));

Instead of rs.getObject(...), use

new Integer(rs.getObject().toString())


You might have to monkey around a bit with the toString() return value, as it might have a decimal in it. In that case,


String val = rs.getObject().toString() ;
Integer key = new Integer(val.subString(0, val.lastIndexOf(".")));

As long as you can get the value out of the database as a numeric string, you are home free.
shivkpr (30) [Avatar] Offline
#7
Re: getevent types and hash map
thanks a lot