POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE
PAGE!On 02 Dec 2004 09:57, hooverphonique wrote:
>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]);
> }
> }
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException
{
Clob clob = rs.getClob(names[0]);
return clob.getSubString(1, (int) clob.length());
}
public void nullSafeSet(PreparedStatement st, Object value, int
index)
throws HibernateException, SQLException
{
st.setClob(index, Hibernate.createClob((String) value));
}
Above two method I can't insert the data into Oracle 9i database;
But When I change below this two method(Use characterStream to char[])
It worked !!
That's amazing !!
Great Thank You hooverphonique
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]);
}
} |