Since Java uses unicode (ucs2) internally for all Strings, the jdbc code
always needs to do character set conversions for all strings it gets
from the database. In the 7.0 drivers this was done by assuming the
database was using the same character set as the default on the client,
which is incorrect for a number of reasons. In 7.1 the jdbc code asks
the database what character set it is using and does the conversion from
the server character set to the java unicode strings.
Now it turns out that Postgres is a little lax in its character set
support, so you can very easily insert char/varchar/text with values
that fall outside the range of valid values for a given character set
(and psql doesn't really care either). However in java since we must do
character set conversion to unicode, it does make a difference and any
values that were inserted that are incorrect with regards to the
database character set will be reported as ?'s in java.
With regards to your specific problem, my guess is that you haven't
created you database with the proper character set for the data you are
storing in it. I am guessing you simply used the default SQL Acsii
character set for your created database and therefore only the first 127
characters are defined. Any characters above 127 will be returned by
java as ?'s.
If this is the case you will need to recreate your database with the
proper character set for the data you are storing in it and then
everything should be fine.
Jani Averbach wrote:
> I have a problem like that:
> The database is postgresql v7.1, with locale-support
> jdk is sun's jdk1.3.0_02
> and jdbc is that one which comes with postgres (type 2).
> Both database and jdbc driver has been build by myself.
> OS: RH 6.2 based linux with 2.4.3 kernel, glibc 2.1.3.
> The problem:
> There is a database which contains fields (the field's type is 'text')
> with scandinavian alphabet. (Especially ÖÄÅöäå (odiaeresis, adiaeresis,
> aring, or in other words, oe, ae, and a with ring above it)).
> The database has been installed, created and used under
> LC_ALL="finnish" and LANG="fi_FI" environment variables in act.
> Ok, the problem:
> When I try to read those field, I get guestion marks instead of those
> 8-bit scandic chars.
> I have been check my java programs and the database. (in fact, same
> problem appears with postgres-7.1/src/interfaces/jdbc/example/psql.java).
> In general, my java environment works fine with 8-bit chars, with psgl
> (not the java one) there is everything very well with those fields with
> 8-bit chars.
> So my question is, am I doing something wrong, or is there a bug in the
> If this is a bug or you need otherwise help or more information, please
> let me know. I will try to help as much as possible to hunt this one
> If I am doing something stupid, I would very likely to know it...
> BR, Jani
> Jani Averbach
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?