Hi all,

I have created a table
create table temp1(a varchar(200));

and then I tried running the following code.

String msg1 = "\u0000abcd";
PreparedStatement preparedStmt =pgConnection.prepareStatement("insert
into temp1 values(?)");
preparedStmt.clearParameters();
preparedStmt.setString(1, msg1);
preparedStmt.executeUpdate();
preparedStmt.close();

And it throws an Exception saying "\0 not allowd"what should I do ? 
How should I insert unicode string using jdbc ?


-- 
"Stand for something, or you will fall for nothing."

Mon, 30 Aug 2004 15:36:37 +0530
chinni <naveen.bysani@gmail.com>
error with unicode thing??
chinni wrote:
> Hi all,
> 
> I have created a table
> create table temp1(a varchar(200));
> 
> and then I tried running the following code.
> 
> String msg1 = "\u0000abcd";
> PreparedStatement preparedStmt =pgConnection.prepareStatement("insert
> into temp1 values(?)");
> preparedStmt.clearParameters();
> preparedStmt.setString(1, msg1);
> preparedStmt.executeUpdate();
> preparedStmt.close();
> 
> And it throws an Exception saying "\0 not allowd"what should I do ? 
> How should I insert unicode string using jdbc ?

AFAIK, you can't store \0 in a text (varchar, ...) field. This is a 
server-side restriction, not a JDBC-specific issue. Any other (16 bit) 
unicode character should be fine assuming it can be represented in your 
DB encoding.

You may want to use bytea and PreparedStatement.setBytes() if you really 
want to store arbitary data.

-O

Mon, 30 Aug 2004 23:40:47 +1200
Oliver Jowett <oliver@opencloud.com>
Re: error with unicode thing??