Thread:
 method 1 and mysql.. 
 hooverphonique   02 Dec 2004, 09:38 
 Re: method 1 and mysql.. 
 hooverphonique   02 Dec 2004, 09:57 
 Re: method 1 and mysql.. 
 monoxxx   10 Aug 2005, 22:41 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: hooverphonique (02 Dec 2004, 09:57) Replies: 1, Views: 36969
Subject: Re: method 1 and mysql..
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]);
		}
	}
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]