Discussion:
How to convert BLOB to String.
Zsolt
2006-03-14 07:54:33 UTC
Permalink
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:
[***@185982c

How can I fix that?

I use ibatis-2.1.7.597.

zsolt
Gustavo Henrique Sberze Ribas
2006-03-14 11:10:38 UTC
Permalink
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-----
Sent: Tuesday, March 14, 2006 4:55 AM
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
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"/>
How can I fix that?
I use ibatis-2.1.7.597.
zsolt
Zsolt
2006-03-14 15:43:07 UTC
Permalink
Thank you Gustavo.

Is it possible to configure ibatis to put the BLOB directly into a string?

Zsolt
-----Original Message-----
Sent: Tuesday, March 14, 2006 12:11 PM
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
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;
}
}
<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-----
Sent: Tuesday, March 14, 2006 4:55 AM
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
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"/>
How can I fix that?
I use ibatis-2.1.7.597.
zsolt
Nathan Maves
2006-03-14 15:59:24 UTC
Permalink
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
Post by Zsolt
Thank you Gustavo.
Is it possible to configure ibatis to put the BLOB directly into a string?
Zsolt
-----Original Message-----
Sent: Tuesday, March 14, 2006 12:11 PM
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
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;
}
}
<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-----
Sent: Tuesday, March 14, 2006 4:55 AM
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
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"/>
How can I fix that?
I use ibatis-2.1.7.597.
zsolt
Balaji
2006-03-27 16:36:45 UTC
Permalink
Does anyone have a custom type handler for Clob - String written that you
can share.

Thanks,

Balaji

----- Original Message -----
From: "Nathan Maves" <***@Sun.COM>
To: <user-***@ibatis.apache.org>
Sent: Tuesday, March 14, 2006 9:59 AM
Subject: Re: How to convert BLOB to String.
Post by Nathan Maves
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
Post by Zsolt
Thank you Gustavo.
Is it possible to configure ibatis to put the BLOB directly into a string?
Zsolt
-----Original Message-----
Sent: Tuesday, March 14, 2006 12:11 PM
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
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;
}
}
<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-----
Sent: Tuesday, March 14, 2006 4:55 AM
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
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"/>
How can I fix that?
I use ibatis-2.1.7.597.
zsolt
Clinton Begin
2006-03-30 03:51:20 UTC
Permalink
iBATIS comes with a BLOB and CLOB type handler....it has for some time now.

Clinton
Post by Balaji
Does anyone have a custom type handler for Clob - String written that you
can share.
Thanks,
Balaji
----- Original Message -----
Sent: Tuesday, March 14, 2006 9:59 AM
Subject: Re: How to convert BLOB to String.
Post by Nathan Maves
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
Post by Zsolt
Thank you Gustavo.
Is it possible to configure ibatis to put the BLOB directly into a string?
Zsolt
-----Original Message-----
Sent: Tuesday, March 14, 2006 12:11 PM
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
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;
}
}
<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-----
Sent: Tuesday, March 14, 2006 4:55 AM
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
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"/>
How can I fix that?
I use ibatis-2.1.7.597.
zsolt
Zsolt
2006-03-30 06:14:03 UTC
Permalink
I don't want to convert all BLOBs to String only for one table.



Zsolt



_____

From: Clinton Begin [mailto:***@gmail.com]
Sent: Thursday, March 30, 2006 5:51 AM
To: user-***@ibatis.apache.org; Balaji
Subject: Re: How to convert BLOB/CLOB to String.




iBATIS comes with a BLOB and CLOB type handler....it has for some time now.

Clinton



On 3/27/06, Balaji < ***@objectec.com <mailto:***@objectec.com> >
wrote:

Does anyone have a custom type handler for Clob - String written that you
can share.

Thanks,

Balaji

----- Original Message -----
From: "Nathan Maves" <***@Sun.COM>
To: < <mailto:user-***@ibatis.apache.org> user-***@ibatis.apache.org>
Sent: Tuesday, March 14, 2006 9:59 AM
Subject: Re: How to convert BLOB to String.
Post by Nathan Maves
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
Post by Zsolt
Thank you Gustavo.
Is it possible to configure ibatis to put the BLOB directly into a string?
Zsolt
-----Original Message-----
Sent: Tuesday, March 14, 2006 12:11 PM
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
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;
}
}
<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-----
Sent: Tuesday, March 14, 2006 4:55 AM
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
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"/>
How can I fix that?
I use ibatis-2.1.7.597.
zsolt
Niels Beekman
2006-03-30 06:54:04 UTC
Permalink
You should really take a look at the docs, it's all there...



Niels



________________________________

From: Zsolt [mailto:***@intland.com]
Sent: donderdag 30 maart 2006 8:14
To: user-***@ibatis.apache.org
Subject: RE: How to convert BLOB/CLOB to String.



I don't want to convert all BLOBs to String only for one table.



Zsolt



________________________________

From: Clinton Begin [mailto:***@gmail.com]
Sent: Thursday, March 30, 2006 5:51 AM
To: user-***@ibatis.apache.org; Balaji
Subject: Re: How to convert BLOB/CLOB to String.




iBATIS comes with a BLOB and CLOB type handler....it has for some time
now.

Clinton

On 3/27/06, Balaji < ***@objectec.com <mailto:***@objectec.com> >
wrote:

Does anyone have a custom type handler for Clob - String written that
you
can share.

Thanks,

Balaji

----- Original Message -----
From: "Nathan Maves" <***@Sun.COM>
To: < user-***@ibatis.apache.org <mailto:user-***@ibatis.apache.org> >
Sent: Tuesday, March 14, 2006 9:59 AM
Subject: Re: How to convert BLOB to String.
Post by Nathan Maves
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
Post by Zsolt
Thank you Gustavo.
Is it possible to configure ibatis to put the BLOB directly into a
string?
Zsolt
-----Original Message-----
Sent: Tuesday, March 14, 2006 12:11 PM
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
Post by Nathan Maves
Post by Zsolt
private
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;
}
}
<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
Post by Nathan Maves
Post by Zsolt
your string.
regards,
--
Gustavo
-----Original Message-----
Sent: Tuesday, March 14, 2006 4:55 AM
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
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"/>
How can I fix that?
I use ibatis-2.1.7.597.
zsolt
Loading...