Re: Using java.lang.Character for "char" data type

From: Lew <noone(at)lewscanon(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Using java.lang.Character for "char" data type
Date: 2010-05-22 01:11:52
Message-ID: ht7b0f$l6j$1@news.albasani.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Kris Jurka wrote:
> It would be possible to support setObject for a Character, but be aware
> that "char" is not a character long, it's a byte long, so it will fail
> on multibyte characters.

I'm a little confused. When you say "char" is a byte long, are you referring
to the SQL type or the Java type? I'm used to seeing the Java type expressed
in lower case and the SQL type in upper case, so please pardon my confusion.

The Java 'char' type is 16 bits wide.

Doesn't the width of the SQL "CHAR" depend on the encoding?

Otherwise how does it handle, say, UTF-8 when you tell the DB to use that?

To put it another way, suppose I enter a String that contains, say, 24 UTF-8
characters, some of which require multibyte encodings, and try to jam it into
a "CHAR(24)" column or a "VARCHAR(24)" column. Will that cause trouble?

The documentation for CHAR and VARCHAR at
<http://www.postgresql.org/docs/8.4/interactive/datatype-character.html>
says
"SQL defines two primary character types: character varying(n) and
character(n), where n is a positive integer. Both of these types can store
strings up to n characters (not bytes) in length."

That seems to contradict what you said.

--
Lew

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Rod 2010-05-22 07:31:23 Re: After server restart I get - An I/O error occured while sending to the backend.
Previous Message Kris Jurka 2010-05-21 22:16:02 Re: Using java.lang.Character for "char" data type