AW: [OJB-developers] Detecting and mapping null Integer values
Brought to you by:
thma
From: Mahler T. <tho...@it...> - 2002-02-14 11:17:49
|
Hi all, I prefer the wasNull() solution as getObject() is Problematic with = several JDBC drivers... I will put this on my todo list ! thanks, Thomas > -----Urspr=FCngliche Nachricht----- > Von: Darren Syzling [mailto:Dar...@cw...] > Gesendet: Donnerstag, 14. Februar 2002 10:45 > An: obj...@li...; > tho...@ho... > Betreff: Re: [OJB-developers] Detecting and mapping null=20 > Integer values >=20 >=20 > It appears to me there are two choices: >=20 > - wasNull >=20 > - getObject using a cast, is there any reason this wouldn't=20 > work ? For example: >=20 > case Types.INTEGER : > { > result =3D (Integer)rs.getObject(columnId); > break; > } >=20 > getObject will return a null reference if the column value is null. >=20 >=20 >=20 > Darren >=20 >=20 >=20 > |--------+-----------------------> > | | "Jakob | > | | Braeuchi" | > | | <jbraeuchi@ho| > | | tmail.com> | > | | | > | | 02/13/02 | > | | 07:44 PM | > | | | > |--------+-----------------------> > =20 > >------------------------------------------------------------- > ---------------| > | =20 > | > | To: "Thomas Mahler"=20 > <tho...@ho...>, Darren | > | Syzling/London/CWB@CWB =20 > | > | cc: =20 > obj...@li... | > | Subject: Re: [OJB-developers] Detecting and=20 > mapping null Integer | > | values =20 > | > =20 > >------------------------------------------------------------- > ---------------| >=20 >=20 >=20 >=20 > hi thomas, >=20 > what about using wasNull of ResultSet ? >=20 > /** > * Reports whether > * the last column read had a value of SQL <code>NULL</code>. > * Note that you must first call one of the <code>getXXX</code> = methods > * on a column to try to read its value and then call > * the method <code>wasNull</code> to see if the value read was > * SQL <code>NULL</code>. > * > * @return <code>true</code> if the last column value read was SQL > * <code>NULL</code> and <code>false</code> otherwise > * @exception SQLException if a database access error occurs > */ > boolean wasNull() throws SQLException; >=20 > hth jakob >=20 > ----- Original Message ----- > From: "Thomas Mahler" <tho...@ho...> > To: "Darren Syzling" <Dar...@cw...> > Cc: <obj...@li...> > Sent: Wednesday, February 13, 2002 8:09 PM > Subject: Re: [OJB-developers] Detecting and mapping null=20 > Integer values >=20 >=20 > > Hi Darren, > > > > Darren Syzling wrote: > > > > > How can I detect null values for Integer, Long, Double=20 > etc Java class > attributes > > > ? Let's say we're mapping an object which has the=20 > following attributes: > > > > > > class Test > > > { > > > Integer id; > > > String name; > > > Integer sales; > > > } > > > > > > > > > Let's assume that both name and sales can be null. When=20 > retrieving this > object > > > from the database using the PersistenceBroker the String=20 > reference will > be null > > > but the sales reference will in fact refer to an Integer=20 > object with a > zero > > > value. If zero is within the valid range how can we=20 > detect that the > value is > > > actually null. > > > > > > This appears to boil down to:=20 > JdbcAccess.getObjectFromColumn. The code > to > > > convert a string looks like: > > > > > > case Types.VARCHAR: > > > result =3D rs.getString(columnId); > > > break; > > > > > > If the string value is null getString will return a null=20 > reference. But > for > > > Integer (and other classes) the following is used: > > > > > > case Types.INTEGER: > > > result =3D new Integer(rs.getInt(columnId)); > > > break; > > > > > > > > > > > I get your point. But: how should the above code look like to = handle > > your problem correctly? I have no idea. > > If you (or somebody else) tell me how this section should=20 > look like I > > will change it! > > > > > > java.sql.ResultSet does not tell you that a column is NULL. It just > > returns a 0. Of course this is wrong. But SUN specified it this = way. > > Or am I missing something? From the java.sql.ResultSet Source: > > > > /** > > * Gets the value of the designated column in the current row > > * of this <code>ResultSet</code> object as > > * an <code>int</code> in the Java programming language. > > * > > * @param columnIndex the first column is 1, the=20 > second is 2, ... > > * @return the column value; if the value is SQL=20 > <code>NULL</code>, > > * the value returned is <code>0</code> > > * @exception SQLException if a database access error occurs > > */ > > int getInt(int columnIndex) throws SQLException; > > > > > > > getInt will return 0 for null and the an integer will be=20 > created with a > zero > > > value. > > > > > > The Conversion Strategy stuff appears too late in the day=20 > to make the > > > conversion. > > > > > > You are right, things are already on the wrong track at=20 > this point.... > > > > How is everybody else handling this or have I missed something ? > > > > > > cu, > > > > Thomas > > > > > > > > > > > > > Thanks > > > Darren > > > > > > > > > > > > > ************************************************************** > ************** > ************************************************************** > ************ > > > This e-mail has been prepared using information believed by = the > author to be > > > reliable and accurate, but Thales Information Systems=20 > Finance makes no > > > warranty as to accuracy or completeness. In particular Thales > Information > > > Systems Finance does not accept responsibility for =20 > changes made to > this > > > e-mail after it was sent. Any opinions expressed in=20 > this document are > those of > > > the author and do not necessarily reflect the opinions=20 > of the company > or its > > > affiliates. They may be subject to change without notice. > > > This e-mail, its content and any files transmitted with it = are > intended > > > solely for the addressee(s) and may be legally = privileged > and/or > > > confidential. Access by any other party is unauthorised=20 > without the > express > > > written permission of the sender. If you have received=20 > this e-mail in > error you > > > may not copy or use the contents, attachments or=20 > information in any > way. > > > Please destroy it and contact the sender via the Thales=20 > Information > Systems > > > Finance switchboard in London at +44 (0) 20 7650 0100 or=20 > via e-mail > return. > > > This message and any attachments have been scanned > > > for viruses prior to leaving the originators network. The=20 > originator > does not > > > guarantee the security of this message and will not be=20 > responsible for > any > > > damages arising from any alteration of this message by a=20 > third party or > as a > > > result of any virus being passed on. > > > > ************************************************************** > ************** > ************************************************************** > ************* > > > > > > > > > > > > _______________________________________________ > > > Objectbridge-developers mailing list > > > Obj...@li... > > >=20 https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > > > > > > > > > > > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > _______________________________________________ Objectbridge-developers mailing list Obj...@li... https://lists.sourceforge.net/lists/listinfo/objectbridge-developers _______________________________________________ Objectbridge-developers mailing list Obj...@li... https://lists.sourceforge.net/lists/listinfo/objectbridge-developers |