On 02 Dec 2004 09:38, hooverphonique wrote:
>I can confirm that the first method (using Clob#getSubString) does
NOT
>work for MySQL, since the Hibernate ClobImpl class does not allow
>extraction of data using getSubString, which is exactly the method
>MySQL uses to get to the character data
Using method 1 (UserType implementation) with the following code in
place of nullSafeSet and nullSafeGet works for me for both reading and
writing CLOBs..
public Object nullSafeGet(ResultSet rs, String[] names,
Object owner) throws HibernateException, SQLException {
Reader reader = rs.getCharacterStream(names[0]);
if (reader == null) return null;
StringBuffer sb = new StringBuffer();
try {
char[] charbuf = new char[4096];
for (int i = reader.read(charbuf); i > 0; i
= reader.read(charbuf)) {
sb.append(charbuf, 0, i);
}
}
catch (IOException e) {
throw new SQLException( e.getMessage() );
}
return sb.toString();
}
public void nullSafeSet(PreparedStatement st, Object value,
int index) throws HibernateException, SQLException {
if (value != null) {
StringReader r = new StringReader( (String)
value );
st.setCharacterStream( index, r, ((String)
value).length() );
} else {
st.setNull(index, sqlTypes()[0]);
}
} |