ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niels Beekman" <n.beek...@wis.nl>
Subject RE: How to map getBytes in iBATIS?
Date Wed, 09 May 2007 19:11:09 GMT
Hi,

I don't believe there is a way to map directly to byte[]. IMHO, byte
arrays should not be used as properties. Maybe you could create a custom
typehandler that maps the byte[] to String.

If I may do another suggestion: avoid doing rs.getBytes() multiple times
for the same column, you'd better do the following:

byte[] myBytes = rs.getBytes(2);
if (rs.wasNull()) {
  // null handling
} else {
  // byte handling
}

This will save you valuable resources and possibly a roundtrip to the
database.

HTH,

Niels

-----Original Message-----
From: Paul Sanders [mailto:tendancer@gmail.com] 
Sent: woensdag 9 mei 2007 20:33
To: user-java@ibatis.apache.org
Subject: How to map getBytes in iBATIS?


I am (still) converting a lot of JDBC code to iBATIS and was wondering
what
people think is the best way to handle something like this:

accountName = (rs.getBytes(2) != null ? 
                                new String(rs.getBytes(2),
DBHandler.STRING_ENCODING_CHARSET) : // "UTF-8"
                                new String(""));

I thought I would define a setAccountName in my (Account) bean that took
a
byte[] as the arg and do the string encoding in the method. But looking
at
the documentation I didn't see a way to map a result parameter to a
byte[],
only a Byte? 

Did I miss something, or is there a way to specify the encoding in the
map?
Or something else?

Thanks

Paul

-- 
View this message in context:
http://www.nabble.com/How-to-map-getBytes-in-iBATIS--tf3717367.html#a103
99620
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Mime
View raw message