ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Balaji" <bal...@objectec.com>
Subject Re: How to convert BLOB/CLOB to String.
Date Mon, 27 Mar 2006 16:36:45 GMT
Does anyone have a custom type handler for Clob - String written that you
can share.

Thanks,

Balaji

----- Original Message ----- 
From: "Nathan Maves" <Nathan.Maves@Sun.COM>
To: <user-java@ibatis.apache.org>
Sent: Tuesday, March 14, 2006 9:59 AM
Subject: Re: How to convert BLOB to String.


> Yes.
>
> All you would have to do is write your own custom type handler.  It
> would do just as Gustavo suggested but you would only have String
> properties in your POJO.
>
> Nathan
> On Mar 14, 2006, at 8:43 AM, Zsolt wrote:
>
> > Thank you Gustavo.
> >
> > Is it possible to configure ibatis to put the BLOB directly into a
> > string?
> >
> > Zsolt
> >
> >
> >> -----Original Message-----
> >> From: Gustavo Henrique Sberze Ribas [mailto:gribas@cpqd.com.br]
> >> Sent: Tuesday, March 14, 2006 12:11 PM
> >> To: user-java@ibatis.apache.org
> >> Subject: RE: How to convert BLOB to String.
> >>
> >> Hello,
> >>
> >> iBATIS can fetch the BLOB as a stream of bytes. One way of doing
> >> what you
> >> want is to create get/setters using byte[] that store/read to/from a
> >> private
> >> String field, ie:
> >>
> >> public class MyBean implements Serializable{
> >>
> >>  private String myString;
> >>
> >>  public void setStringAsByteArray(byte[] b) {
> >> myString = String(b);
> >>  }
> >>  public byte[] getStringAsByteArray() {
> >> return myString.getBytes();
> >>  }
> >>
> >>  public void setMyString(String s) {
> >> myString = s;
> >>  }
> >>  public String getMyString() {
> >> return myString;
> >>  }
> >> }
> >>
> >> and your result map:
> >>
> >> <resultMap class="MyBean" id="MyBeanResultMap">
> >>  <result column="BLOB_COLUMN" property="stringAsByteArray"
> >> jdbcType="BLOB"/>
> >> </resultMap>
> >>
> >> That way you also have the chance to set the appropriate encoding to
> >> your string.
> >>
> >>
> >> regards,
> >>
> >> --
> >> Gustavo
> >>
> >>
> >>
> >>> -----Original Message-----
> >>> From: Zsolt [mailto:zkoppanylist@intland.com]
> >>> Sent: Tuesday, March 14, 2006 4:55 AM
> >>> To: user-java@ibatis.apache.org
> >>> Subject: How to convert BLOB to String.
> >>>
> >>>
> >>> Hi,
> >>>
> >>> I have a BLOB field in mysql-4.1.18 and want to get that as
> >>> String. The
> >>> property I use as follows:
> >>>
> >>> setArgument(String arg) {...}
> >>>
> >>> In the mapping file I tried to use the code below but that
> >>> didn't help.
> >>>   <result property="argument" column="argument_types"
> >>> jdbcType="BLOB"
> >>>     javaType="java.lang.String"/>
> >>>
> >>> Instead of the string I get something like below:
> >>> [B@185982c
> >>>
> >>> How can I fix that?
> >>>
> >>> I use ibatis-2.1.7.597.
> >>>
> >>> zsolt
> >>>
> >>>
> >>>
> >>>
> >
>
>
>


Mime
View raw message