Extended from http://wubaodan.javaeye.com/blog/85672
Thank you,wubaodan.

Basically, this problem is produced when the string exceeded the Oracle thin driver limitation.
Here are the descriptions of the two different drivers.(Thank wubaodan again.)


1、JDBC OCI driver:
"If the value of NLS_LANG is set to a character set other than US7ASCII or WE8ISO8859P1, then the driver uses UTF8 as the client character set. This happens automatically and does not require any user intervention. OCI then converts the data from the database character set to UTF8. The JDBC OCI driver then passes the UTF8 data to the JDBC Class Library where the UTF8 data is converted to UTF-16."
 
2、JDBC thin driver:
"If the database character set is neither ASCII (US7ASCII) nor ISO Latin1 (WE8ISO8859P1), then the JDBC thin driver must impose size restrictions for SQL CHAR bind parameters that are more restrictive than normal database size limitations. This is necessary to allow for data expansion during conversion.
The JDBC thin driver checks SQL CHAR bind sizes when a setXXX() method (except for the setCharacterStream() method) is called. If the data size exceeds the size restriction, then the driver returns a SQL exception (SQLException: Data size bigger than max size for this type) from the setXXX() call. This limitation is necessary to avoid the chance of data corruption when conversion of character data occurs and increases the length of the data. This limitation is enforced in the following situations:
(1)Using the JDBC thin driver
(2)Using binds (not defines)
(3)Using SQL CHAR datatypes
(4)Connecting to a database whose character set is neither ASCII (US7ASCII) nor ISO Latin1 (WE8ISO8859P1)
When the database character set is neither US7ASCII nor WE8ISO8859P1, the JDBC thin driver converts Java UTF-16 characters to UTF-8 encoding bytes for SQL CHAR binds. The UTF-8 encoding bytes are then transferred to the database, and the database converts the UTF-8 encoding bytes to the database character set encoding."


My case is when inserting a 687-Traditional-Chinese-Character string ,the error message is the same as the message mentioned above.

The usage of
setCharacterStream() is :
void setCharacterStream(int parameterIndex,
Reader reader,
int length)
throws SQLException
And this is my solution:
stat.setCharacterStream(10,new StringReader(f_message), f_message.length());

swangs 發表在 痞客邦 PIXNET 留言(0) 人氣()