I have a java String that has the apostrophe character ‘ (which is different from ').
The length of my string containing that character is 35 and can be verified using the .length method.
However, when passing this string containing the ‘ to a PreparedStatement object using the setString method pstmt.setString(1, description);, the length of the string gets translated to a 37 character string which can be seen from the following error message I am getting:
java.sql.BatchUpdateException: ORA-12899: value too large for column "DESCRIPTION" (actual: 37, maximum: 35)
What would be the most elegant way to handle this problem?
If you want to check the length of your String before inserting it in DB, you have to convert it to the charset used by your DB. It can be done with
for instance
see http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#String%28byte%5B%5D,%20java.lang.String%29