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

Поиск
Список
Период
Сортировка
От Lew
Тема Re: Using java.lang.Character for "char" data type
Дата
Msg-id ht7b0f$l6j$1@news.albasani.net
обсуждение исходный текст
Ответ на Re: Using java.lang.Character for "char" data type  (Kris Jurka <books@ejurka.com>)
Ответы Re: Using java.lang.Character for "char" data type
Re: Using java.lang.Character for "char" data type
Список 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

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Lew
Дата:
Сообщение: Re: Using java.lang.Character for "char" data type
Следующее
От: Lew
Дата:
Сообщение: Re: JDBC Driver and timezones