views:

234

answers:

2

I have a Java application decoding a UTF-8 encoded String received over the wire and saving it to a varchar column in my database (SQL Server 2000). I am saving the record using JDBC's CallableStatement (calling the setString method to set the parameter for this column).

The problem I'm seeing is that a particular String has been written that contains ASCII value 0 (NUL). This suggests to me that SQL server cannot represent a particular Unicode character and the JDBC driver has decided to substitute in ASCII value 0, although I may be wrong.

  • Has anyone else encountered this problem?
  • Is there a mechanism I can use to cause the CallableStatement call to fail in this situation?

Ideally I would like to guarantee that data has been saved exactly as specified, or else "fail fast".

My database character set is Latin1_General_AS_CS.

Thanks in advance.

A: 

Just a WAG, but would using .setBytes(String parameterName, byte[] x) do trick? The byte array would come from myString.getBytes(). You might want to try using using different character sets with getBytes(), too.

Stu Thompson
+1  A: 

You need to be using 'NVARCHAR' type in the database.

pjp