Обсуждение: Information on JDBC driver src code, please help

Поиск
Список
Период
Сортировка

Information on JDBC driver src code, please help

От
"Gulshan Babajee"
Дата:
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

Re: Information on JDBC driver src code, please help

От
Kris Jurka
Дата:

On Mon, 5 Jun 2006, Gulshan Babajee wrote:

> 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

LATIN1 does not support the Euro.  Try LATIN9.  You do not need to adjust
the client_encoding, only the server encoding.

Kris Jurka