Information on JDBC driver src code, please help

From: "Gulshan Babajee" <gulshan(dot)babajee(at)parabolemaurice(dot)com>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Information on JDBC driver src code, please help
Date: 2006-06-05 04:31:22
Message-ID: 60BA566AF1B3934FA866BAC17483675943D14D@mail.parabolemaurice.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi,

am actually using postgres8.1.4 and JDBC driver 8.1-4.0.7. With this am having a problem with database encoding.
I've created a db with encoding LATIN1 and having problem when inserting for example the euro character '€' in my db

After search the jdbc doc I found the following:

charSet = String

The character set to use for data sent to the database or recieved from the database. This property is only relevent for server versions less than or equal to 7.2. The 7.3 release was the first with multibyte support compiled by default and the driver uses its character set translation facilities instead of trying to do it itself.

allowEncodingChanges = boolean

When using the V3 protocol the driver monitors changes in certain server configuration parameters that should not be touched by end users. The client_encoding setting is set by the driver and should not be altered..............


Now I've downloaded the source code of the JDBC driver and in the class 'ConnectionFactoryImpl.java' I found this:

if (dbVersion.compareTo("7.3") >= 0)
{
// set encoding to be unicode; set datestyle; ensure autocommit is on
// (no-op on 7.4, but might be needed under 7.3)
// The begin/commit is to avoid leaving a transaction open if we're talking to a
// 7.3 server that defaults to autocommit = off.

if (Driver.logDebug)
Driver.debug("Switching to UNICODE client_encoding");

runSetupQuery(protoConnection, "begin; set autocommit = on; set client_encoding = 'UNICODE'; commit", false);
protoConnection.setEncoding(Encoding.getDatabaseEncoding("UNICODE"));
}
else
{
String dbEncoding = (results[1] == null ? null : protoConnection.getEncoding().decode(results[1]));
if (Driver.logDebug)
{
Driver.debug("Specified charset: " + charSet);
Driver.debug("Database encoding: " + dbEncoding);
}

if (charSet != null)
{
// Explicitly specified encoding.
protoConnection.setEncoding(Encoding.getJVMEncoding(charSet));
}
else if (dbEncoding != null)
{
// Use database-supplied encoding.
protoConnection.setEncoding(Encoding.getDatabaseEncoding(dbEncoding));
}
else
{
// Fall back to defaults.
// XXX is this ever reached?
protoConnection.setEncoding(Encoding.defaultEncoding());
}
}


>From the code I found that if my postgresql version is above or equal to 7.3, the encoding is FORCED to 'UNICODE', else the encoding is the database encoding.
Why it is like this and how can I set the client_encoding to LATIN1 or is there a way so that I can insert the euro character without havin encoding problem

thanks in advance

gulshan

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.8.1/355 - Release Date: 6/2/2006

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2006-06-05 05:22:05 Re: Information on JDBC driver src code, please help
Previous Message rcolmegna@tiscali.it 2006-06-03 07:27:47 R: Re: CachedRowSet insertion problem with serial PK