Re: Using java.lang.Character for "char" data type - Mailing list pgsql-jdbc

From Lew
Subject Re: Using java.lang.Character for "char" data type
Date
Msg-id ht7b0f$l6j$1@news.albasani.net
Whole thread Raw
In response to Re: Using java.lang.Character for "char" data type  (Kris Jurka <books@ejurka.com>)
Responses Re: Using java.lang.Character for "char" data type  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Re: Using java.lang.Character for "char" data type  (Radosław Smogura <mail@smogura.eu>)
List 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 by date:

Previous
From: Lew
Date:
Subject: Re: Using java.lang.Character for "char" data type
Next
From: Lew
Date:
Subject: Re: JDBC Driver and timezones