ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher.Mathru...@sybase.com
Subject Re: Sybase JConnect 5.5 & CLOB
Date Wed, 22 Mar 2006 22:50:02 GMT

<br><font size=2 face="sans-serif">I think your problem is that you need
to tell iBatis the column type that you are fetching. This is from a previous
email in the archive. </font>
<br>
<br><font size=2><tt><i>iBATIS can fetch the BLOB as a stream of bytes.
One way of doing what you <br>
want is to create get/setters using byte[] that store/read to/from a private
<br>
String field, ie:<br>
<br>
public class MyBean implements Serializable{<br>
<br>
 &nbsp;private String myString;<br>
<br>
 &nbsp;public void setStringAsByteArray(byte[] b) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
myString = String(b);<br>
 &nbsp;}<br>
 &nbsp;public byte[] getStringAsByteArray() {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
return myString.getBytes();<br>
 &nbsp;}<br>
<br>
 &nbsp;public void setMyString(String s) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
myString = s;<br>
 &nbsp;}<br>
 &nbsp;public String getMyString() {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
return myString;<br>
 &nbsp;}<br>
}<br>
<br>
and your result map:<br>
<br>
&lt;resultMap class=&quot;MyBean&quot; id=&quot;MyBeanResultMap&quot;&gt;<br>
 &nbsp;&lt;result column=&quot;BLOB_COLUMN&quot; property=&quot;stringAsByteArray&quot;
jdbcType=&quot;BLOB&quot;/&gt;<br>
&lt;/resultMap&gt;<br>
<br>
That way you also have the chance to set the appropriate encoding to<br>
your string.</i></tt></font>
<br>
<br>
<br><font size=2 face="sans-serif"><br>
Chris Mathrusse<br>
christopher.mathrusse@sybase.com<br>
Sybase, Inc<br>
One Sybase Drive<br>
Dublin, CA 94568<br>
(925) 236-5553</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>&quot;Balaji&quot;
&lt;balaji@objectec.com&gt;</b>
</font>
<p><font size=1 face="sans-serif">03/22/2006 02:41 PM</font>
<table border>
<tr valign=top>
<td bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to<br>
user-java@ibatis.apache.org</font></div></table>
<br>
<td width=59%>
<table width=100%>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td valign=top><font size=1 face="sans-serif">&lt;user-java@ibatis.apache.org&gt;</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td valign=top><font size=1 face="sans-serif">Re: Sybase JConnect 5.5 &amp;
CLOB</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=2 face="Arial">Chris,</font>
<br><font size=3>&nbsp;</font>
<br><font size=2 face="Arial">now i am getting </font>
<br><font size=2 color=blue face="Arial">Cause: java.sql.SQLException:
JZ0TE: Attempted conversion between an illegal pair of types. Valid database
datatypes are: 'varbinay, long binary, binary, image</font>
<br><font size=2 color=blue face="Arial">&nbsp;</font>
<br><font size=2 face="Arial">Where should i be changing the datatype in
POJO or resultMap? </font>
<br><font size=2 face="Arial">&nbsp;</font>
<br><font size=2 face="Arial">here is the code (msg field is defined as
Text datatype in db). &nbsp;</font>
<br><font size=2 face="Arial">&nbsp;public class Email &nbsp;{ &nbsp;
<br>
 &nbsp; private String from_addr;<br>
 &nbsp; private String to_addr;<br>
 &nbsp; private String subject;</font>
<br><font size=2 face="Arial">&nbsp; &nbsp;</font><font size=2
color=#3f7f5f face="Arial">//private
String msg;</font><font size=2 face="Arial"><br>
 &nbsp; private byte[] msg;<br>
 &nbsp; <br>
 public byte[] getMsg() {<br>
 &nbsp;return msg;<br>
 }<br>
 &nbsp;<br>
 public void setMsg(byte[] bs) {<br>
 &nbsp;msg = bs;<br>
 }</font>
<br><font size=2 face="Arial">----------------------------------------------------------------------------------------------</font>
<br><font size=2 face="Arial">&nbsp;&lt;resultMap class=&quot;Email&quot;
id=&quot;EmailResult&quot;&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;result column=&quot;from_addr&quot;
property=&quot;from_addr&quot;
/&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;result column=&quot;to_addr&quot;
property=&quot;to_addr&quot;
/&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;result column=&quot;subject&quot;
property=&quot;subject&quot;
/&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;result column=&quot;msg&quot;
property=&quot;msg&quot;
jdbcType=&quot;CLOB&quot; /&gt;<br>
 &lt;/resultMap&gt;</font>
<br><font size=3>&nbsp;</font>
<br><font size=2 face="Arial">&nbsp;&lt;select id=&quot;getEmailById&quot;
parameterClass=&quot;int&quot; resultMap=&quot;EmailResult&quot;&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;SELECT &nbsp;from_addr, to_addr, subject,
msg<br>
 &nbsp; &nbsp; &nbsp; &nbsp;FROM &nbsp; &nbsp;email_store<br>
 &nbsp; &nbsp; &nbsp; &nbsp;WHERE &nbsp; id_email = #VALUE#<br>
 &lt;/select&gt;</font>
<br><font size=2 face="Arial">------------------------------------------------------------------------------------------------------</font>
<br><font size=3>&nbsp;</font>
<br><font size=2 face="Arial">Thanks</font>
<br><font size=3>&nbsp;</font>
<br><font size=2 face="Arial">Balaji</font>
<br><font size=3>----- Original Message ----- </font>
<br><font size=3><b>From:</b> </font><a href=mailto:Christopher.Mathrusse@sybase.com><font
size=3 color=blue><u>Christopher.Mathrusse@sybase.com</u></font></a><font
size=3>
</font>
<br><font size=3><b>To:</b> </font><a href="mailto:user-java@ibatis.apache.org"><font
size=3 color=blue><u>user-java@ibatis.apache.org</u></font></a><font
size=3>
</font>
<br><font size=3><b>Sent:</b> Wednesday, March 22, 2006 4:18 PM</font>
<br><font size=3><b>Subject:</b> Re: Sybase JConnect 5.5 &amp;
CLOB</font>
<br>
<br><font size=2 face="sans-serif"><br>
You should be reading the CLOB out of the database into a byte[] rather
than a String. From there you can convert it into a String and apply any
encoding that might be necessary.</font><font size=3> </font><font size=2
face="sans-serif"><br>
<br>
Chris Mathrusse</font><font size=2 color=blue face="sans-serif"><u><br>
</u></font><a href=mailto:christopher.mathrusse@sybase.com><font size=2
color=blue face="sans-serif"><u>christopher.mathrusse@sybase.com</u></font></a><font
size=2 face="sans-serif"><br>
Sybase, Inc<br>
One Sybase Drive<br>
Dublin, CA 94568<br>
(925) 236-5553</font><font size=3> <br>
<br>
</font>
<table width=100%>
<tr valign=top>
<td width=48%><font size=1 face="sans-serif"><b>&quot;Balaji&quot;
&lt;</b></font><a href=mailto:balaji@objectec.com><font size=1 color=blue
face="sans-serif"><b><u>balaji@objectec.com</u></b></font></a><font
size=1 face="sans-serif"><b>&gt;</b>
</font>
<p><font size=1 face="sans-serif">03/22/2006 02:15 PM</font><font size=3>
</font>
<br>
<table border=4 width=100%>
<tr valign=top>
<td width=100% bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to</font><font
size=1 color=blue face="sans-serif"><u><br>
</u></font><a href="mailto:user-java@ibatis.apache.org"><font size=1
color=blue face="sans-serif"><u>user-java@ibatis.apache.org</u></font></a></div></table>
<p>
<td width=51%>
<br>
<table width=100%>
<tr>
<td width=20%>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td width=79% valign=top><font size=1 face="sans-serif">&lt;user-java@ibatis.apache.org&gt;</font><font
size=3>
</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td valign=top><font size=1 face="sans-serif">Sybase JConnect 5.5 &amp;
CLOB</font></table>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=49%>
<td width=50%></table>
<br></table>
<br><font size=3><br>
<br>
</font><font size=2><tt><br>
When i try to read a 'TEXT' datatype field from Sybase 12.0 database &amp;<br>
JConnect 5.5,<br>
- datatype in POJO is String &nbsp;(also tried java.sql.Clob)<br>
- jdbcType in resultMap is 'CLOB'<br>
<br>
i get the following error message shown below. &nbsp;Looks like getClob(string)<br>
is not implemented in Jconnect yet.<br>
<br>
Does anyone know how to get this to work, any workaround?<br>
<br>
Thanks<br>
Balaji<br>
<br>
/***************************************************************************<br>
*********************/<br>
 &nbsp; &nbsp; &nbsp; ERROR MESSAGE<br>
/***************************************************************************<br>
*********************/<br>
Caused by:<br>
java.lang.UnsupportedOperationException: The method<br>
com.sybase.jdbc2.jdbc.SybResultSet.getClob(String) is not supported and<br>
should not be called.<br>
at<br>
com.sybase.jdbc2.jdbc.ErrorMessage.raiseRuntimeException(ErrorMessage.java:7<br>
63)<br>
at com.sybase.jdbc2.utils.Debug.notSupported(Debug.java:366)<br>
at com.sybase.jdbc2.jdbc.SybResultSet.getClob(SybResultSet.java:1371)<br>
at<br>
com.ibatis.sqlmap.engine.type.ResultGetterImpl.getClob(ResultGetterImpl.java<br>
:108)<br>
at<br>
com.ibatis.sqlmap.engine.type.ClobTypeHandlerCallback.getResult(ClobTypeHand<br>
lerCallback.java:28)<br>
at<br>
com.ibatis.sqlmap.engine.type.CustomTypeHandler.getResult(CustomTypeHandler.<br>
java:52)<br>
at<br>
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getPrimitiveResultMap<br>
pingValue(BasicResultMap.java:552)<br>
at<br>
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getResults(BasicResul<br>
tMap.java:311)<br>
at<br>
com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.jav<br>
a:390)<br>
at<br>
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java<br>
:184)<br>
at<br>
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(<br>
GeneralStatement.java:205)<br>
at<br>
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWith<br>
Callback(GeneralStatement.java:173)<br>
at<br>
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForO<br>
bject(GeneralStatement.java:104)<br>
at<br>
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapEx<br>
ecutorDelegate.java:561)<br>
at<br>
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapEx<br>
ecutorDelegate.java:536)<br>
at<br>
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSession<br>
Impl.java:93)<br>
at<br>
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientIm<br>
pl.java:70)<br>
<br>
<br>
----- Original Message ----- <br>
From: &quot;Nathan Maves&quot; &lt;Nathan.Maves@Sun.COM&gt;<br>
To: &lt;user-java@ibatis.apache.org&gt;<br>
Sent: Tuesday, March 21, 2006 5:51 PM<br>
Subject: Re: multiple setters<br>
<br>
<br>
&gt; Ahhh yeah... &nbsp;not good don't have them. &nbsp;:)<br>
&gt;<br>
&gt; They are against the java bean specification.<br>
&gt;<br>
&gt; Nathan<br>
&gt; On Mar 21, 2006, at 4:38 PM, Ben Munat wrote:<br>
&gt;<br>
&gt; &gt; Hey All... I seem to remember someone talking recently about<br>
&gt; &gt; difficulties with a property set by ibatis having multiple setters.<br>
&gt; &gt; Does this ring a bell?<br>
&gt; &gt;<br>
&gt; &gt; b<br>
&gt;<br>
&gt;<br>
&gt;<br>
<br>
</tt></font><font size=3><br>
</font>
<br>

Mime
View raw message